Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable repository search in parent directories #675

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions internal/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"

"github.com/bluekeyes/go-gitdiff/gitdiff"
Expand Down Expand Up @@ -119,12 +120,22 @@ func applyPatches(srcDir, workingDir string, modFiles map[string]bool, patches [
}
}

cmd := exec.Command("git", "apply")
// If one of parent folders of workingDir contains repository, set current directory is not enough because git
// by default treats workingDir as a subfolder of repository, so it will break git apply. Adding --git-dir flag blocks this behavior.
cmd := exec.Command("git", "--git-dir", workingDir, "apply", "--verbose")
cmd.Dir = workingDir
cmd.Stdin = bytes.NewReader(bytes.Join(patches, []byte("\n")))
if err := cmd.Run(); err != nil {
out, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}

// Running git without errors does not guarantee that all patches have been applied.
// Make sure that all passed patches have been applied correctly.
rx := regexp.MustCompile(`(?m)^Applied patch .+ cleanly\.$`)
if appliedPatches := len(rx.FindAllIndex(out, -1)); appliedPatches != len(patches) {
return nil, fmt.Errorf("expected %d applied patches, actually %d:\n\n%s", len(patches), appliedPatches, string(out))
}
return mod, nil
}

Expand Down
3 changes: 3 additions & 0 deletions testdata/script/linker.txtar
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[!short] [exec:git] exec git init -q
[!short] [exec:git] env GARBLE_CACHE_DIR=$WORK/linker-cache

garble build
exec ./main
! cmp stderr main.stderr
Expand Down