5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
status.go 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
package git
import "fmt"
import "bytes"
// Status represents the current status of a Worktree.
// The key of the map is the path of the file.
type Status map[string]*FileStatus
// File returns the FileStatus for a given path, if the FileStatus doesn't
// exists a new FileStatus is added to the map using the path as key.
func (s Status) File(path string) *FileStatus {
if _, ok := (s)[path]; !ok {
s[path] = &FileStatus{Worktree: Untracked, Staging: Untracked}
}
return s[path]
}
// IsClean returns true if all the files aren't in Unmodified status.
func (s Status) IsClean() bool {
for _, status := range s {
if status.Worktree != Unmodified || status.Staging != Unmodified {
return false
}
}
return true
}
func (s Status) String() string {
buf := bytes.NewBuffer(nil)
for path, status := range s {
if status.Staging == Unmodified && status.Worktree == Unmodified {
continue
}
if status.Staging == Renamed {
path = fmt.Sprintf("%s -> %s", path, status.Extra)
}
fmt.Fprintf(buf, "%c%c %s\n", status.Staging, status.Worktree, path)
}
return buf.String()
}
// FileStatus contains the status of a file in the worktree
type FileStatus struct {
// Staging is the status of a file in the staging area
Staging StatusCode
// Worktree is the status of a file in the worktree
Worktree StatusCode
// Extra contains extra information, such as the previous name in a rename
Extra string
}
// StatusCode status code of a file in the Worktree
type StatusCode byte
const (
Unmodified StatusCode = ' '
Untracked StatusCode = '?'
Modified StatusCode = 'M'
Added StatusCode = 'A'
Deleted StatusCode = 'D'
Renamed StatusCode = 'R'
Copied StatusCode = 'C'
UpdatedButUnmerged StatusCode = 'U'
)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.0.0-rc10

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385