Skip to content

Commit 7e123fb

Browse files
committed
issue 178: fetch the repo dir with rev-parse --git-dir
Since is returns the .git dir directly, it is not more needed to concatenate .git.
1 parent 91f563d commit 7e123fb

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

cache/repo_cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ func (c *RepoCache) writeIdentityCache() error {
350350
}
351351

352352
func bugCacheFilePath(repo repository.Repo) string {
353-
return path.Join(repo.GetPath(), ".git", "git-bug", bugCacheFile)
353+
return path.Join(repo.GetPath(), "git-bug", bugCacheFile)
354354
}
355355

356356
func identityCacheFilePath(repo repository.Repo) string {
357-
return path.Join(repo.GetPath(), ".git", "git-bug", identityCacheFile)
357+
return path.Join(repo.GetPath(), "git-bug", identityCacheFile)
358358
}
359359

360360
func (c *RepoCache) buildCache() error {
@@ -706,7 +706,7 @@ func (c *RepoCache) Pull(remote string) error {
706706
}
707707

708708
func repoLockFilePath(repo repository.Repo) string {
709-
return path.Join(repo.GetPath(), ".git", "git-bug", lockfile)
709+
return path.Join(repo.GetPath(), "git-bug", lockfile)
710710
}
711711

712712
// repoIsAvailable check is the given repository is locked by a Cache.

commands/select/select.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) {
137137
}
138138

139139
func selectFilePath(repo repository.RepoCommon) string {
140-
return path.Join(repo.GetPath(), ".git", "git-bug", selectFile)
140+
return path.Join(repo.GetPath(), "git-bug", selectFile)
141141
}

input/input.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func QueryEditorInput(repo repository.RepoCommon, preQuery string) (string, erro
239239
// launchEditorWithTemplate will launch an editor as launchEditor do, but with a
240240
// provided template.
241241
func launchEditorWithTemplate(repo repository.RepoCommon, fileName string, template string) (string, error) {
242-
path := fmt.Sprintf("%s/.git/%s", repo.GetPath(), fileName)
242+
path := fmt.Sprintf("%s/%s", repo.GetPath(), fileName)
243243

244244
err := ioutil.WriteFile(path, []byte(template), 0644)
245245

@@ -254,13 +254,13 @@ func launchEditorWithTemplate(repo repository.RepoCommon, fileName string, templ
254254
// method blocks until the editor command has returned.
255255
//
256256
// The specified filename should be a temporary file and provided as a relative path
257-
// from the repo (e.g. "FILENAME" will be converted to ".git/FILENAME"). This file
257+
// from the repo (e.g. "FILENAME" will be converted to "[<reporoot>/].git/FILENAME"). This file
258258
// will be deleted after the editor is closed and its contents have been read.
259259
//
260260
// This method returns the text that was read from the temporary file, or
261261
// an error if any step in the process failed.
262262
func launchEditor(repo repository.RepoCommon, fileName string) (string, error) {
263-
path := fmt.Sprintf("%s/.git/%s", repo.GetPath(), fileName)
263+
path := fmt.Sprintf("%s/%s", repo.GetPath(), fileName)
264264
defer os.Remove(path)
265265

266266
editor, err := repo.GetCoreEditor()

repository/git.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/MichaelMure/git-bug/util/lamport"
1818
)
1919

20-
const createClockFile = "/.git/git-bug/create-clock"
21-
const editClockFile = "/.git/git-bug/edit-clock"
20+
const createClockFile = "/git-bug/create-clock"
21+
const editClockFile = "/git-bug/edit-clock"
2222

2323
// ErrNotARepo is the error returned when the git repo root wan't be found
2424
var ErrNotARepo = errors.New("not a git repository")
@@ -76,10 +76,11 @@ func NewGitRepo(path string, witnesser Witnesser) (*GitRepo, error) {
7676
repo := &GitRepo{Path: path}
7777

7878
// Check the repo and retrieve the root path
79-
stdout, err := repo.runGitCommand("rev-parse", "--show-toplevel")
79+
stdout, err := repo.runGitCommand("rev-parse", "--git-dir")
8080

81-
// for some reason, "git rev-parse --show-toplevel" return nothing
82-
// and no error when inside a ".git" dir
81+
// Now dir is fetched with "git rev-parse --git-dir". May be it can
82+
// still return nothing in some cases. Then empty stdout check is
83+
// kept.
8384
if err != nil || stdout == "" {
8485
return nil, ErrNotARepo
8586
}

0 commit comments

Comments
 (0)