go-git reports a file as Untracked while it should be Unmodified

好久不见. 提交于 2020-07-10 10:27:23

问题


I am trying to check the status of a particular file in a git repo using go-git library.

This is the code I am attempting to run:

    repo, err := git.PlainOpen(fullPathToRepo)
    if err != nil {
        return false, fmt.Errorf("ERROR: Unable to open repository %s\n%s", fullPathToRepo, err)
    }

    workTree, err := repo.Worktree()
    if err != nil {
        return false, fmt.Errorf("ERROR: Unable to open worktree for repository %s\n%s", fullPathToRepo, err)
    }
    workTreeStatus, err := workTree.Status()
    if err != nil {
        return false, fmt.Errorf("ERROR: Unable to retrieve worktree status for repository %s\n%s", fullPathToRepo, err)
    }
    fmt.Printf("%q\n", workTreeStatus.File("releases/filename").Worktree)
    fmt.Printf("%q\n", workTreeStatus.File("/Users/panteliskaramolegkos/myrepo/filename/releases/faros.yaml").Worktree)
    return workTreeStatus.IsClean(), nil

i.e. I am attempting to use both the full as also the relevant (to the repo) path to the file I want to check.

In both cases what is printed out is the following:

`?`
`?`

According to the documentation however, this corresponds to an Untracked file.

The specific file is properly committed and checked in.

Why am I getting the wrong status code?

来源:https://stackoverflow.com/questions/62738651/go-git-reports-a-file-as-untracked-while-it-should-be-unmodified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!