зеркало из https://github.com/golang/dep.git
gps: Insulate against .git as file
`git ls-remote` was being run without a current working directory, which - for some versions of git - has the unfortunate side effect of still looking for a local .git in the cwd hierarchy, and failing if that .git is a file instead of a directory (as it might be if the user is working beneath a git submodule). This relocates the call to somewhere safer, under gps' control, so that we've a better (though not foolproof) guarantee of not colliding with a .git file. Fixes #1338.
This commit is contained in:
Родитель
4ecb1d1fb9
Коммит
6da79c0318
|
@ -10,6 +10,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -36,6 +37,7 @@ func testSourceGateway(t *testing.T) {
|
|||
os.RemoveAll(cachedir)
|
||||
cancelFunc()
|
||||
}()
|
||||
os.Mkdir(filepath.Join(cachedir, "sources"), 0777)
|
||||
|
||||
do := func(wantstate sourceState) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
|
|
|
@ -242,6 +242,16 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
|
|||
r := s.repo
|
||||
|
||||
cmd := commandContext(ctx, "git", "ls-remote", r.Remote())
|
||||
// We want to invoke from a place where it's not possible for there to be a
|
||||
// .git file instead of a .git directory, as git ls-remote will choke on the
|
||||
// former and erroneously quit. However, we can't be sure that the repo
|
||||
// exists on disk yet at this point; if it doesn't, then instead use the
|
||||
// parent of the local path, as that's still likely a good bet.
|
||||
if r.CheckLocal() {
|
||||
cmd.SetDir(r.LocalPath())
|
||||
} else {
|
||||
cmd.SetDir(filepath.Dir(r.LocalPath()))
|
||||
}
|
||||
// Ensure no prompting for PWs
|
||||
cmd.SetEnv(append([]string{"GIT_ASKPASS=", "GIT_TERMINAL_PROMPT=0"}, os.Environ()...))
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
|
|
@ -53,6 +53,7 @@ func testGitSourceInteractions(t *testing.T) {
|
|||
t.Errorf("removeAll failed: %s", err)
|
||||
}
|
||||
}()
|
||||
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
|
||||
|
||||
n := "github.com/sdboyer/gpkt"
|
||||
un := "https://" + n
|
||||
|
@ -149,6 +150,7 @@ func testGopkginSourceInteractions(t *testing.T) {
|
|||
t.Errorf("removeAll failed: %s", err)
|
||||
}
|
||||
}()
|
||||
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
|
||||
|
||||
tfunc := func(opath, n string, major uint64, evl []Version) {
|
||||
un := "https://" + opath
|
||||
|
@ -533,6 +535,8 @@ func TestGitSourceListVersionsNoHEAD(t *testing.T) {
|
|||
defer h.Cleanup()
|
||||
h.TempDir("smcache")
|
||||
cpath := h.Path("smcache")
|
||||
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
|
||||
|
||||
h.TempDir("repo")
|
||||
repoPath := h.Path("repo")
|
||||
|
||||
|
@ -599,6 +603,7 @@ func TestGitSourceListVersionsNoDupes(t *testing.T) {
|
|||
t.Errorf("removeAll failed: %s", err)
|
||||
}
|
||||
}()
|
||||
os.Mkdir(filepath.Join(cpath, "sources"), 0777)
|
||||
|
||||
n := "github.com/carolynvs/deptest-importers"
|
||||
un := "https://" + n
|
||||
|
|
Загрузка…
Ссылка в новой задаче