fork of go-git with some jj specific features
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.2.0 70 lines 1.8 kB view raw
1package git 2 3import "fmt" 4import "bytes" 5 6// Status represents the current status of a Worktree. 7// The key of the map is the path of the file. 8type Status map[string]*FileStatus 9 10// File returns the FileStatus for a given path, if the FileStatus doesn't 11// exists a new FileStatus is added to the map using the path as key. 12func (s Status) File(path string) *FileStatus { 13 if _, ok := (s)[path]; !ok { 14 s[path] = &FileStatus{Worktree: Untracked, Staging: Untracked} 15 } 16 17 return s[path] 18} 19 20// IsClean returns true if all the files aren't in Unmodified status. 21func (s Status) IsClean() bool { 22 for _, status := range s { 23 if status.Worktree != Unmodified || status.Staging != Unmodified { 24 return false 25 } 26 } 27 28 return true 29} 30 31func (s Status) String() string { 32 buf := bytes.NewBuffer(nil) 33 for path, status := range s { 34 if status.Staging == Unmodified && status.Worktree == Unmodified { 35 continue 36 } 37 38 if status.Staging == Renamed { 39 path = fmt.Sprintf("%s -> %s", path, status.Extra) 40 } 41 42 fmt.Fprintf(buf, "%c%c %s\n", status.Staging, status.Worktree, path) 43 } 44 45 return buf.String() 46} 47 48// FileStatus contains the status of a file in the worktree 49type FileStatus struct { 50 // Staging is the status of a file in the staging area 51 Staging StatusCode 52 // Worktree is the status of a file in the worktree 53 Worktree StatusCode 54 // Extra contains extra information, such as the previous name in a rename 55 Extra string 56} 57 58// StatusCode status code of a file in the Worktree 59type StatusCode byte 60 61const ( 62 Unmodified StatusCode = ' ' 63 Untracked StatusCode = '?' 64 Modified StatusCode = 'M' 65 Added StatusCode = 'A' 66 Deleted StatusCode = 'D' 67 Renamed StatusCode = 'R' 68 Copied StatusCode = 'C' 69 UpdatedButUnmerged StatusCode = 'U' 70)