Skip to content

Commit

Permalink
Fetch a github pull request (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofpa committed Jan 22, 2021
1 parent b3e036a commit 24fd3b2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/buildcontext/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
RecurseSubmodules: getRecurseSubmodules(g.opts.GitRecurseSubmodules),
}
if len(parts) > 1 {
options.ReferenceName = plumbing.ReferenceName(parts[1])
if !strings.HasPrefix(parts[1], "refs/pull/") {
options.ReferenceName = plumbing.ReferenceName(parts[1])
}
}

if branch := g.opts.GitBranch; branch != "" {
Expand All @@ -81,7 +83,22 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
logrus.Debugf("Getting source from reference %s", options.ReferenceName)
r, err := git.PlainClone(directory, false, &options)

if err == nil && len(parts) > 2 {
if err != nil {
return directory, err
}

if len(parts) > 1 && strings.HasPrefix(parts[1], "refs/pull/") {

err = r.Fetch(&git.FetchOptions{
RemoteName: "origin",
RefSpecs: []config.RefSpec{config.RefSpec(parts[1] + ":" + parts[1])},
})
if err != nil {
return directory, err
}
}

if len(parts) > 2 {
// ... retrieving the commit being pointed by HEAD
_, err := r.Head()
if err != nil {
Expand Down

0 comments on commit 24fd3b2

Please sign in to comment.