Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit bac3c7c

Browse files
authored
Merge pull request #817 from laverya/dont-delete-local-git-directories
don't delete the .git directory if fetched from a local file
2 parents d7756a3 + 79223b9 commit bac3c7c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkg/specs/gogetter/go_getter.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ func (g *GoGetter) GetFiles(ctx context.Context, upstream, savePath string) (str
4545
return "", errors2.FetchFilesError{Message: err.Error()}
4646
}
4747

48-
// if there is a `.git` directory, remove it - it's dynamic and will break the content hash used by `ship update`
49-
gitPresent, err := g.FS.Exists(path.Join(savePath, ".git"))
50-
if err != nil {
51-
return "", errors.Wrap(err, "check for .git directory")
52-
}
53-
if gitPresent {
54-
err := g.FS.RemoveAll(path.Join(savePath, ".git"))
48+
// check if the upstream is a local file - if it is, we shouldn't remove the .git directory
49+
fileDetector := getter.FileDetector{}
50+
if _, foundFile, err := fileDetector.Detect(upstream, savePath); !foundFile || err != nil {
51+
// if there is a `.git` directory, remove it - it's dynamic and will break the content hash used by `ship update`
52+
gitPresent, err := g.FS.Exists(path.Join(savePath, ".git"))
5553
if err != nil {
56-
return "", errors.Wrap(err, "remove .git directory")
54+
return "", errors.Wrap(err, "check for .git directory")
55+
}
56+
if gitPresent {
57+
err := g.FS.RemoveAll(path.Join(savePath, ".git"))
58+
if err != nil {
59+
return "", errors.Wrap(err, "remove .git directory")
60+
}
5761
}
62+
debug.Log("event", "gitPresent.check", "gitPresent", gitPresent)
5863
}
59-
debug.Log("event", "gitPresent.check", "gitPresent", gitPresent)
6064

6165
return filepath.Join(savePath, g.Subdir), nil
6266
}

0 commit comments

Comments
 (0)