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

Fixed issue #2387 #2391

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/download/abs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ func Test_getPackageRepoURL(t *testing.T) {
func TestABSPKGBUILDRepo(t *testing.T) {
t.Parallel()
cmdRunner := &testRunner{}
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux"
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --origin=origin --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux"
if os.Getuid() == 0 {
ld := "systemd-run"
if path, _ := exec.LookPath(ld); path != "" {
ld = path
}
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux", ld)
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --origin=origin --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux", ld)
}

cmdBuilder := &testGitBuilder{
Expand Down
4 changes: 2 additions & 2 deletions pkg/download/aur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ func TestGetAURPkgbuild(t *testing.T) {
// THEN a clone command should be formed
func TestAURPKGBUILDRepo(t *testing.T) {
t.Parallel()
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin"
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --origin=origin https://aur.archlinux.org/yay-bin.git yay-bin"
if os.Getuid() == 0 {
ld := "systemd-run"
if path, _ := exec.LookPath(ld); path != "" {
ld = path
}
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress https://aur.archlinux.org/yay-bin.git yay-bin", ld)
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --origin=origin https://aur.archlinux.org/yay-bin.git yay-bin", ld)
}

cmdRunner := &testRunner{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/download/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func downloadGitRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
gitArgs = append(gitArgs, pkgURL, pkgName)

cloneArgs := make([]string, 0, len(gitArgs)+4)
cloneArgs = append(cloneArgs, "clone", "--no-progress")
cloneArgs = append(cloneArgs, "clone", "--no-progress", "--origin=origin")
cloneArgs = append(cloneArgs, gitArgs...)
cmd := cmdBuilder.BuildGitCmd(ctx, dest, cloneArgs...)

Expand Down
20 changes: 20 additions & 0 deletions pkg/settings/exe/cmd_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var gitDenyList = mapset.NewThreadUnsafeSet(
"GIT_WORK_TREE",
"GIT_DIR",
)
var gitConfigOverrides = map[string]string{
"clone.defaultRemoteName": "origin",
}

type GitCmdBuilder interface {
Runner
Expand Down Expand Up @@ -113,6 +116,20 @@ func gitFilteredEnv() []string {
return env
}

func gitConfigEnv() []string {
var env []string

count := 0
for key, value := range gitConfigOverrides {
env = append(env, fmt.Sprintf("GIT_CONFIG_KEY_%d=%s", count, key))
env = append(env, fmt.Sprintf("GIT_CONFIG_VALUE_%d=%s", count, value))
count++
}
env = append(env, "GIT_CONFIG_COUNT="+strconv.Itoa(count))

return env
}

func (c *CmdBuilder) BuildGitCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd {
args := make([]string, len(c.GitFlags), len(c.GitFlags)+len(extraArgs))
copy(args, c.GitFlags)
Expand All @@ -128,6 +145,7 @@ func (c *CmdBuilder) BuildGitCmd(ctx context.Context, dir string, extraArgs ...s
cmd := exec.CommandContext(ctx, c.GitBin, args...)

cmd.Env = gitFilteredEnv()
cmd.Env = append(cmd.Env, gitConfigEnv()...)

cmd = c.deElevateCommand(ctx, cmd)

Expand All @@ -153,6 +171,8 @@ func (c *CmdBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs
cmd := exec.CommandContext(ctx, c.MakepkgBin, args...)
cmd.Dir = dir

cmd.Env = append(cmd.Env, gitConfigEnv()...)

cmd = c.deElevateCommand(ctx, cmd)

return cmd
Expand Down