aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikola Knezevic <nikola@knezevic.ch>2020-05-30 12:33:38 +0200
committerNikola Knezevic <nikola@knezevic.ch>2020-05-30 12:33:38 +0200
commitfb38459d6e58508245553380cccc03c0dbaa1542 (patch)
tree165dd31244da093d4e67b8c14f4716dea23c2012 /src
parent77007d4eabcf7090d1d3fbbdf84a67fb2262cf78 (diff)
Ensure we restrict refspec interpretation while fetching
As `git fetch` may chose to interpret refspec to it's liking, ensure that we only pass refs that begin with `refs/` as is, otherwise, prepend them with `refs/heads`. Otherwise, branches named `heads/foo` (I know it's bad, but it's allowed), would be fetched as `foo`, instead of `heads/foo`.
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/git.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index e069057eb..75ce5ee8b 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -282,7 +282,10 @@ struct GitInput : Input
// FIXME: git stderr messes up our progress indicator, so
// we're using --quiet for now. Should process its stderr.
try {
- runProgram("git", true, { "-C", repoDir, "fetch", "--quiet", "--force", "--", actualUrl, fmt("%s:%s", *input->ref, *input->ref) });
+ auto fetchRef = input->ref->compare(0, 5, "refs/") == 0
+ ? *input->ref
+ : "refs/heads/" + *input->ref;
+ runProgram("git", true, { "-C", repoDir, "fetch", "--quiet", "--force", "--", actualUrl, fmt("%s:%s", fetchRef, fetchRef) });
} catch (Error & e) {
if (!pathExists(localRefFile)) throw;
warn("could not update local clone of Git repository '%s'; continuing with the most recent version", actualUrl);