diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-12-22 17:07:13 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-12-22 17:07:13 +0100 |
| commit | e4d68911c533a750022ddfe06aff080ca6cf678b (patch) | |
| tree | d3effd306daa9ead8cc542ff3177465a3a09b620 /pkg/prompt | |
| parent | 5d966f103efe0647e9f073db8fe91ade056d056a (diff) | |
| download | gofu-e4d68911c533a750022ddfe06aff080ca6cf678b.tar.gz | |
prettyprompt: understand git packed-refs
Diffstat (limited to 'pkg/prompt')
| -rw-r--r-- | pkg/prompt/git.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/pkg/prompt/git.go b/pkg/prompt/git.go index 144beb5..9ace960 100644 --- a/pkg/prompt/git.go +++ b/pkg/prompt/git.go @@ -93,7 +93,23 @@ func getRepoStatusField(repo *gitRepo) string { refSpecDisplay := strings.TrimPrefix(refSpec, "refs/") refSpecDisplay = strings.TrimPrefix(refSpecDisplay, "heads/") - //read file corresponding to refspec to find commit + //attempt to read packed-refs + bytes, err = ioutil.ReadFile(filepath.Join(repo.GitDir, "packed-refs")) + if err == nil { + for _, line := range strings.Split(string(bytes), "\n") { + line = strings.TrimSpace(line) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + fields := strings.Fields(line) + if len(fields) == 2 && fields[1] == refSpec { + return formatRepoStatusField(refSpecDisplay, fields[0]) + } + } + } + + //if reading packed-refs did not work or did not yield the commit ID, read + //file corresponding to refspec to find commit ID bytes, err = ioutil.ReadFile(filepath.Join(repo.GitDir, refSpec)) commitID := strings.TrimSpace(string(bytes)) if err != nil { |
