diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-12-23 07:48:10 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-12-23 07:48:10 +0100 |
commit | dcaf17c75d925531ba399a211e63664784d96821 (patch) | |
tree | 6ff3464e3c5cbf5bb7caf01ae6f30ede32b5dbc9 /builtin/fetch.c | |
parent | The fourth batch (diff) | |
parent | pull, fetch: fix segfault in --set-upstream option (diff) | |
download | git-dcaf17c75d925531ba399a211e63664784d96821.tar.xz git-dcaf17c75d925531ba399a211e63664784d96821.zip |
Merge branch 'ab/fetch-set-upstream-while-detached'
"git fetch --set-upstream" did not check if there is a current
branch, leading to a segfault when it is run on a detached HEAD,
which has been corrected.
* ab/fetch-set-upstream-while-detached:
pull, fetch: fix segfault in --set-upstream option
Diffstat (limited to 'builtin/fetch.c')
-rw-r--r-- | builtin/fetch.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index e45185cf9c..f1fe73a3e0 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1643,6 +1643,16 @@ static int do_fetch(struct transport *transport, } } if (source_ref) { + if (!branch) { + const char *shortname = source_ref->name; + skip_prefix(shortname, "refs/heads/", &shortname); + + warning(_("could not set upstream of HEAD to '%s' from '%s' when " + "it does not point to any branch."), + shortname, transport->remote->name); + goto skip; + } + if (!strcmp(source_ref->name, "HEAD") || starts_with(source_ref->name, "refs/heads/")) install_branch_config(0, |