diff options
-rw-r--r-- | remote.c | 34 | ||||
-rwxr-xr-x | t/t2024-checkout-dwim.sh | 18 |
2 files changed, 41 insertions, 11 deletions
@@ -1611,6 +1611,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; @@ -1622,17 +1643,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 6ecb559465..468a000e4b 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 |