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

Commit 2b7a080

Browse files
authored
Merge pull request #1376 from sdboyer/dotgit-file
gps: Insulate against .git as file
2 parents 832c144 + 6da79c0 commit 2b7a080

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

gps/source_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io/ioutil"
1111
"log"
1212
"os"
13+
"path/filepath"
1314
"reflect"
1415
"testing"
1516

@@ -36,6 +37,7 @@ func testSourceGateway(t *testing.T) {
3637
os.RemoveAll(cachedir)
3738
cancelFunc()
3839
}()
40+
os.Mkdir(filepath.Join(cachedir, "sources"), 0777)
3941

4042
do := func(wantstate sourceState) func(t *testing.T) {
4143
return func(t *testing.T) {

gps/vcs_source.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
242242
r := s.repo
243243

244244
cmd := commandContext(ctx, "git", "ls-remote", r.Remote())
245+
// We want to invoke from a place where it's not possible for there to be a
246+
// .git file instead of a .git directory, as git ls-remote will choke on the
247+
// former and erroneously quit. However, we can't be sure that the repo
248+
// exists on disk yet at this point; if it doesn't, then instead use the
249+
// parent of the local path, as that's still likely a good bet.
250+
if r.CheckLocal() {
251+
cmd.SetDir(r.LocalPath())
252+
} else {
253+
cmd.SetDir(filepath.Dir(r.LocalPath()))
254+
}
245255
// Ensure no prompting for PWs
246256
cmd.SetEnv(append([]string{"GIT_ASKPASS=", "GIT_TERMINAL_PROMPT=0"}, os.Environ()...))
247257
out, err := cmd.CombinedOutput()

gps/vcs_source_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func testGitSourceInteractions(t *testing.T) {
5353
t.Errorf("removeAll failed: %s", err)
5454
}
5555
}()
56+
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
5657

5758
n := "github.com/sdboyer/gpkt"
5859
un := "https://" + n
@@ -149,6 +150,7 @@ func testGopkginSourceInteractions(t *testing.T) {
149150
t.Errorf("removeAll failed: %s", err)
150151
}
151152
}()
153+
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
152154

153155
tfunc := func(opath, n string, major uint64, evl []Version) {
154156
un := "https://" + opath
@@ -533,6 +535,8 @@ func TestGitSourceListVersionsNoHEAD(t *testing.T) {
533535
defer h.Cleanup()
534536
h.TempDir("smcache")
535537
cpath := h.Path("smcache")
538+
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
539+
536540
h.TempDir("repo")
537541
repoPath := h.Path("repo")
538542

@@ -599,6 +603,7 @@ func TestGitSourceListVersionsNoDupes(t *testing.T) {
599603
t.Errorf("removeAll failed: %s", err)
600604
}
601605
}()
606+
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
602607

603608
n := "github.com/carolynvs/deptest-importers"
604609
un := "https://" + n

0 commit comments

Comments
 (0)