Skip to content

Commit

Permalink
Merge pull request #24433 from cuyl/fix-git-fetch
Browse files Browse the repository at this point in the history
fix: fetch error with depth 1
  • Loading branch information
k8s-ci-robot authored Nov 23, 2021
2 parents dd34e73 + ffa529b commit 62adef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions prow/pod-utils/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,22 @@ func (g *gitCtx) commandsForBaseRef(refs prowapi.Refs, gitUserName, gitUserEmail
commands = append(commands, g.gitFetch(fetchArgs...))
}

{
fetchArgs := append([]string{}, depthArgs...)
fetchArgs = append(fetchArgs, g.repositoryURI, refs.BaseRef)
commands = append(commands, g.gitFetch(fetchArgs...))
}

var fetchRef string
var target string
if refs.BaseSHA != "" {
fetchRef = refs.BaseSHA
target = refs.BaseSHA
} else {
fetchRef = refs.BaseRef
target = "FETCH_HEAD"
}

{
fetchArgs := append([]string{}, depthArgs...)
fetchArgs = append(fetchArgs, g.repositoryURI, fetchRef)
commands = append(commands, g.gitFetch(fetchArgs...))
}

// we need to be "on" the target branch after the sync
// so we need to set the branch to point to the base ref,
// but we cannot update a branch we are on, so in case we
Expand Down
8 changes: 4 additions & 4 deletions prow/pod-utils/clone/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestCommandsForRefs(t *testing.T) {
fetchRetries,
},
retryCommand{
cloneCommand{dir: "/go/src/github.com/org/repo", command: "git", args: []string{"fetch", "https://github.com/org/repo.git", "master"}},
cloneCommand{dir: "/go/src/github.com/org/repo", command: "git", args: []string{"fetch", "https://github.com/org/repo.git", "abcdef"}},
fetchRetries,
},
cloneCommand{dir: "/go/src/github.com/org/repo", command: "git", args: []string{"checkout", "abcdef"}},
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestCommandsForRefs(t *testing.T) {
fetchRetries,
},
retryCommand{
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "https://github.enterprise.com/org/repo.git", "master"}},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "https://github.enterprise.com/org/repo.git", "abcdef"}},
fetchRetries,
},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"checkout", "abcdef"}},
Expand All @@ -661,7 +661,7 @@ func TestCommandsForRefs(t *testing.T) {
cloneCommand{dir: "/", command: "mkdir", args: []string{"-p", "/go/src/github.enterprise.com/org/repo"}},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"init"}},
retryCommand{
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "https://github.enterprise.com/org/repo.git", "master"}},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "https://github.enterprise.com/org/repo.git", "abcdef"}},
fetchRetries,
},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"checkout", "abcdef"}},
Expand All @@ -688,7 +688,7 @@ func TestCommandsForRefs(t *testing.T) {
cloneCommand{dir: "/", command: "mkdir", args: []string{"-p", "/go/src/github.enterprise.com/org/repo"}},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"init"}},
retryCommand{
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "--depth", "2", "https://github.enterprise.com/org/repo.git", "master"}},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"fetch", "--depth", "2", "https://github.enterprise.com/org/repo.git", "abcdef"}},
fetchRetries,
},
cloneCommand{dir: "/go/src/github.enterprise.com/org/repo", command: "git", args: []string{"checkout", "abcdef"}},
Expand Down

0 comments on commit 62adef3

Please sign in to comment.