зеркало из https://github.com/golang/dep.git
Add vendor/.git exists check in SafeWriter.Write
This commit is contained in:
Родитель
640786cb6c
Коммит
8630423b3b
|
@ -294,6 +294,14 @@ func (sw *SafeWriter) Write(root string, sm gps.SourceManager) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure vendor/.git is preserved if present
|
||||
if hasDotGit(vpath) {
|
||||
err = os.Rename(filepath.Join(vpath, ".git"), filepath.Join(td, "vendor/.git"))
|
||||
if _, ok := err.(*os.LinkError); ok {
|
||||
return errors.Wrap(err, "failed to preserve vendor/.git")
|
||||
}
|
||||
}
|
||||
|
||||
// Move the existing files and dirs to the temp dir while we put the new
|
||||
// ones in, to provide insurance against errors for as long as possible.
|
||||
type pathpair struct {
|
||||
|
@ -526,6 +534,16 @@ func deleteDirs(toDelete []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// hasDotGit checks if a given path has .git file or directory in it.
|
||||
func hasDotGit(path string) bool {
|
||||
gitfilepath := filepath.Join(path, ".git")
|
||||
_, err := os.Stat(gitfilepath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type byLen []string
|
||||
|
||||
func (a byLen) Len() int { return len(a) }
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
package dep
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -522,3 +524,17 @@ func TestSafeWriter_DiffLocks(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasDotGit(t *testing.T) {
|
||||
// Create a tempdir with .git file
|
||||
td, err := ioutil.TempDir(os.TempDir(), "dotGitFile")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
os.OpenFile(td+string(filepath.Separator)+".git", os.O_CREATE, 0777)
|
||||
if !hasDotGit(td) {
|
||||
t.Fatal("Expected hasDotGit to find .git")
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче