Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

File status is reported as Untracked for tracked+unmodified files? #1300

@martin-helmich

Description

@martin-helmich

I'm using (more like, trying to use) this library to determine if certain files in a Git repository have been modified or not.

This was my approach (error handling omitted for brevity):

repo, _ := git.PlainOpen(".")
tree, _ := repo.Worktree()
status, _ := repo.Status()

fileStatus := status.File("path/to/unmodified-file")

The file path/to/unmodified-file is (unsurprisingly) already committed to the repo and unmodified (both in staging and worktree). In this case, I would expect that fileStatus.Worktree == git.Unmodified. However, the following happens:

fmt.Println(string(fileStatus.Worktree))  // expected=" " actual="?"
fmt.Println(fileStatus.Worktree == git.Unmodified) // expected="true" actual="false"
fmt.Println(fileStatus.Worktree == git.Untracked) // expected="false" actual="true"

This seems to occur because Untracked is kind of the "default" status:

go-git/status.go

Lines 15 to 21 in 1a7db85

func (s Status) File(path string) *FileStatus {
if _, ok := (s)[path]; !ok {
s[path] = &FileStatus{Worktree: Untracked, Staging: Untracked}
}
return s[path]
}

I'm unsure if this behaviour is intentional and I've just misunderstood how Status is supposed to work (in which case I might suggest at least clearing up the docs a little bit) or if this is an actual bug. 🤷‍♂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions