Skip to content

Commit

Permalink
zip: set PWD consistently for commands in subdirectories
Browse files Browse the repository at this point in the history
Some platforms (notably macOS) use symlinks for /tmp, so if we fail to
set PWD appropriately, any resulting errors may refer to the wrong
directory, making those errors more confusing.

Change-Id: Ibc899d7aca138d9e016171e34e7e4aab4895a4df
Reviewed-on: https://go-review.googlesource.com/c/mod/+/375914
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Aug 17, 2022
1 parent 046e8b3 commit f994a2a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zip/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func filesInGitRepo(dir, rev, subdir string) ([]File, error) {
cmd.Args = append(cmd.Args, subdir)
}
cmd.Dir = dir
cmd.Env = append(os.Environ(), "PWD="+dir)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -679,11 +680,12 @@ func isGitRepo(dir string) bool {
stdout := &bytes.Buffer{}
cmd := exec.Command("git", "rev-parse", "--git-dir")
cmd.Dir = dir
cmd.Env = append(os.Environ(), "PWD="+dir)
cmd.Stdout = stdout
if err := cmd.Run(); err != nil {
return false
}
gitDir := strings.TrimSpace(string(stdout.Bytes()))
gitDir := strings.TrimSpace(stdout.String())
if !filepath.IsAbs(gitDir) {
gitDir = filepath.Join(dir, gitDir)
}
Expand Down

0 comments on commit f994a2a

Please sign in to comment.