Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit c790045

Browse files
committed
Support GitHub Pull Request refspec
This patch introduces support for settings a dep constraint's revision to a commit that exists in a GitHub pull request. Issue #1583 outlines how GitHub PRs use a non-standard Git refspec, `+refs/pull/PR_ID`, to store the commit built by CI systems such as Travis-CI. This patch includes a new refspec when Git's VCS handler performs a fetch operation. The refspec `+refs/pull/*:refs/pull/%x/*` is used where `%x` is an MD5 hash of the constraint's configured remote location. This ensures that if the remote location is changed, the refspec will point to a new location locally. This unblocks build failures occurring in rexray/gocsi#71 and rexray/gocsi#80. cc @sbezverk @sdboyer
1 parent d81b4d0 commit c790045

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

gps/vcs_repo.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func newVcsLocalErrorOr(err error, args []string, out, msg string) error {
8181
return vcs.NewLocalError(msg, errors.Wrapf(err, "command failed: %v", args), out)
8282
}
8383

84+
const envGitRefspecs = "DEP_GIT_REFSPECS"
85+
8486
func (r *gitRepo) get(ctx context.Context) error {
8587
cmd := commandContext(
8688
ctx,
@@ -99,17 +101,26 @@ func (r *gitRepo) get(ctx context.Context) error {
99101
"unable to get repository")
100102
}
101103

104+
// If there are additional refspecs defined then make sure they are fetched
105+
// after the initial clone operation.
106+
if os.Getenv(envGitRefspecs) != "" {
107+
return r.fetch(ctx)
108+
}
109+
102110
return nil
103111
}
104112

105113
func (r *gitRepo) fetch(ctx context.Context) error {
106114
cmd := commandContext(
107115
ctx,
108116
"git",
109-
"fetch",
110-
"--tags",
111-
"--prune",
112-
r.RemoteLocation,
117+
append([]string{
118+
"fetch",
119+
"--tags",
120+
"--prune",
121+
r.RemoteLocation,
122+
},
123+
strings.Split(os.Getenv(envGitRefspecs), ",")...)...,
113124
)
114125
cmd.SetDir(r.LocalPath())
115126
// Ensure no prompting for PWs

0 commit comments

Comments
 (0)