diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-01-07 12:40:59 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-01-07 12:41:00 -0800 |
commit | da178ac793047c41e4806a3c32fb421992642683 (patch) | |
tree | 65b6053da74fc52bccd25efe3687b71c3af57dd4 | |
parent | c5b9256360b06efb9453c1627b78b14598e288b8 (diff) | |
parent | 05e73682cd28eeaf6d949badefd85b94244fca3f (diff) | |
download | git-da178ac793047c41e4806a3c32fb421992642683.tar.gz git-da178ac793047c41e4806a3c32fb421992642683.tar.xz |
Merge branch 'jc/checkout-local-track-report'
The report from "git checkout" on a branch that builds on another
local branch by setting its branch.*.merge to branch name (not a
full refname) incorrectly said that the upstream is gone.
* jc/checkout-local-track-report:
checkout: report upstream correctly even with loosely defined branch.*.merge
-rw-r--r-- | remote.c | 34 | ||||
-rwxr-xr-x | t/t2024-checkout-dwim.sh | 18 |
2 files changed, 41 insertions, 11 deletions
@@ -1631,6 +1631,27 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, } } +static void set_merge(struct branch *ret) +{ + char *ref; + unsigned char sha1[20]; + int i; + + ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge)); + for (i = 0; i < ret->merge_nr; i++) { + ret->merge[i] = xcalloc(1, sizeof(**ret->merge)); + ret->merge[i]->src = xstrdup(ret->merge_name[i]); + if (!remote_find_tracking(ret->remote, ret->merge[i]) || + strcmp(ret->remote_name, ".")) + continue; + if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]), + sha1, &ref) == 1) + ret->merge[i]->dst = ref; + else + ret->merge[i]->dst = xstrdup(ret->merge_name[i]); + } +} + struct branch *branch_get(const char *name) { struct branch *ret; @@ -1642,17 +1663,8 @@ struct branch *branch_get(const char *name) ret = make_branch(name, 0); if (ret && ret->remote_name) { ret->remote = remote_get(ret->remote_name); - if (ret->merge_nr) { - int i; - ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge)); - for (i = 0; i < ret->merge_nr; i++) { - ret->merge[i] = xcalloc(1, sizeof(**ret->merge)); - ret->merge[i]->src = xstrdup(ret->merge_name[i]); - if (remote_find_tracking(ret->remote, ret->merge[i]) - && !strcmp(ret->remote_name, ".")) - ret->merge[i]->dst = xstrdup(ret->merge_name[i]); - } - } + if (ret->merge_nr) + set_merge(ret); } return ret; } diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh index 6ecb55946..468a000e4 100755 --- a/t/t2024-checkout-dwim.sh +++ b/t/t2024-checkout-dwim.sh @@ -185,4 +185,22 @@ test_expect_success 'checkout <branch> -- succeeds, even if a file with the same test_branch_upstream spam repo_c spam ' +test_expect_success 'loosely defined local base branch is reported correctly' ' + + git checkout master && + git branch strict && + git branch loose && + git commit --allow-empty -m "a bit more" && + + test_config branch.strict.remote . && + test_config branch.loose.remote . && + test_config branch.strict.merge refs/heads/master && + test_config branch.loose.merge master && + + git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect && + git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual && + + test_cmp expect actual +' + test_done |