-
Notifications
You must be signed in to change notification settings - Fork 788
File reported as Untracked while it is commited (i.e. Unmodified) #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
FWIW, I came up with the following hack: // cheap workaround for https://github.com/go-git/go-git/issues/119
func status(path string) (*git.FileStatus, error) {
cmd := exec.Command("git", "status", "-s", path)
output, err := cmd.Output()
if err != nil {
return nil, err
}
fs := git.FileStatus{
Staging: git.Untracked,
Worktree: git.Untracked,
}
// TODO: detect merge conflicts etc.
if len(output) >= 2 {
fs.Staging = git.StatusCode(output[0])
fs.Worktree = git.StatusCode(output[1])
}
return &fs, nil
} |
Workaround: var fileStatusMapping = map[git.StatusCode]string{
git.Unmodified: "",
git.Untracked: "Untracked",
git.Modified: "Modified",
git.Added: "Added",
git.Deleted: "Deleted",
git.Renamed: "Renamed",
git.Copied: "Copied",
git.UpdatedButUnmerged: "Updated",
}
func (r *Repo) FileStatus(filename string) (string, string, error) {
w, err := r.worktree()
if err != nil {
return "", "", err
}
s, err := w.Status()
if err != nil {
return "", "", err
}
if s != nil {
var untracked bool
if s.IsUntracked(filename) {
untracked = true
}
fileStatus := s.File(filename)
if !untracked && fileStatus.Staging == git.Untracked &&
fileStatus.Worktree == git.Untracked {
fileStatus.Staging = git.Unmodified
fileStatus.Worktree = git.Unmodified
}
return fileStatusMapping[fileStatus.Staging], fileStatusMapping[fileStatus.Worktree], nil
}
return "", "", nil
} NOTE: |
This has been open for a while and is a clear bug, isn't it? Having the same problem. |
Does anyone else have an issue in detecting changes with status? If I run git status, I get some information, while with file status, the list is empty. |
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while. This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed. We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active. Thanks for your understanding and cooperation! |
…lding it empty. Fixes go-git#119
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while. This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed. We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active. Thanks for your understanding and cooperation! |
The fix for go-git#119 improves the Worktree.Status() behaviour by preloading all existing files and setting their status to unmodified. This makes it more reliable when doing per file status verification, however breaks backwards compatibility in two ways: - Increased execution time and space: the preloading can be slow in very large repositories and will increase memory usage when representing the state. - Behaviour: the previous behaviour returned a map with a small subset of entries. The new behaviour will include a new entry for every file within the repository. Signed-off-by: Paulo Gomes <pjbgf@linux.com>
The fix for go-git#119 improves the Worktree.Status() behaviour by preloading all existing files and setting their status to unmodified. Which makes it more reliable when doing per file status verification, however breaks backwards compatibility in two ways: - Increased execution time and space: the preloading can be slow in very large repositories and will increase memory usage when representing the state. - Behaviour: the previous behaviour returned a map with a small subset of entries. The new behaviour will include a new entry for every file within the repository. This commit introduces reverts the change in the default behaviour, and introduces StatusWithOptions so that users can opt-in the new option. Signed-off-by: Paulo Gomes <pjbgf@linux.com>
…lding it empty. Fixes go-git#119
The fix for go-git#119 improves the Worktree.Status() behaviour by preloading all existing files and setting their status to unmodified. Which makes it more reliable when doing per file status verification, however breaks backwards compatibility in two ways: - Increased execution time and space: the preloading can be slow in very large repositories and will increase memory usage when representing the state. - Behaviour: the previous behaviour returned a map with a small subset of entries. The new behaviour will include a new entry for every file within the repository. This commit introduces reverts the change in the default behaviour, and introduces StatusWithOptions so that users can opt-in the new option. Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Assuming my full path to repo is
/Users/panteliskaramolegkos/myrepo
, I am going through the following steps to check the status of a specific file (code below is part of a specific function)In both cases (i.e. using full or relative path, the following gets printed out
According to the documentation, this corresponds to status
Untracked
However the file is committed (and pushed to the remote, but I guess this is irrelevant)
The text was updated successfully, but these errors were encountered: