diff options
| author | Stefan Majewsky <stefan.majewsky@sap.com> | 2022-04-01 14:35:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-01 14:35:33 +0200 |
| commit | be0e424eecec3fec19ba3518f8fd1bb07b6908dc (patch) | |
| tree | 81229238e7cd25f1ad248da2c16e523d529cfd72 /internal/rtree | |
| parent | d35e5fb09bfac1fa381e4ed004ea24a6025e36f4 (diff) | |
| parent | 1c5cc4947add7cfc5fdbe0cce1e67450ce5d2bd3 (diff) | |
| download | gofu-be0e424eecec3fec19ba3518f8fd1bb07b6908dc.tar.gz | |
Merge pull request #8 from SuperSandro2000/dot-git
Always append .git when searching to better support copied URLs from GitHub UI
Diffstat (limited to 'internal/rtree')
| -rw-r--r-- | internal/rtree/index.go | 8 | ||||
| -rw-r--r-- | internal/rtree/repo.go | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/internal/rtree/index.go b/internal/rtree/index.go index b802ef8..226689a 100644 --- a/internal/rtree/index.go +++ b/internal/rtree/index.go @@ -128,8 +128,7 @@ func (i *Index) Rebuild() error { //check if existing index entries are still checked out var newRepos []*Repo for _, repo := range i.Repos { - gitDirPath := filepath.Join(repo.AbsolutePath(), ".git") - fi, err := os.Stat(gitDirPath) + fi, err := os.Stat(repo.GitDirPath()) switch { case err == nil: // in a normal repo .git is a directory but when the repo is a submodule of another repo @@ -139,7 +138,7 @@ func (i *Index) Rebuild() error { newRepos = append(newRepos, repo) continue } - return fmt.Errorf("expected repository at %s, but is not a directory or file", gitDirPath) + return fmt.Errorf("expected repository at %s, but is not a directory or file", repo.GitDirPath()) case !os.IsNotExist(err): return err } @@ -227,7 +226,8 @@ func (i *Index) FindRepo(rawRemoteURL string, allowClone bool) (*Repo, error) { for _, repo := range i.Repos { isCandidate := false for _, remote := range repo.Remotes { - if remoteURL == remote.URL { + // be flexible about .git ending in remote + if remoteURL == remote.URL || remoteURL+".git" == remote.URL || remoteURL == remote.URL+".git" { return repo, nil } if basename == path.Base(remote.URL.CanonicalURL()) { diff --git a/internal/rtree/repo.go b/internal/rtree/repo.go index 59f3811..f710666 100644 --- a/internal/rtree/repo.go +++ b/internal/rtree/repo.go @@ -49,6 +49,11 @@ func (r Repo) AbsolutePath() string { return filepath.Join(RootPath, r.CheckoutPath) } +//GitDirPath returns the path of the .git directory of this repo. +func (r Repo) GitDirPath() string { + return filepath.Join(r.AbsolutePath(), ".git") +} + //NewRepoFromAbsolutePath initializes a Repo instance by scanning the existing //checkout at the given path. func NewRepoFromAbsolutePath(path string) (repo Repo, err error) { |
