mirror of
https://github.com/git/git.git
synced 2024-06-02 14:06:12 +02:00
Merge branch 'jk/help-unknown-ref-fix'
Improve the code to show args with potential typo that cannot be interpreted as a commit-ish. * jk/help-unknown-ref-fix: help_unknown_ref(): check for refname ambiguity help_unknown_ref(): duplicate collected refnames
This commit is contained in:
commit
8d32d2552e
8
help.c
8
help.c
|
@ -754,19 +754,19 @@ static int append_similar_ref(const char *refname, const struct object_id *oid,
|
||||||
{
|
{
|
||||||
struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
|
struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
|
||||||
char *branch = strrchr(refname, '/') + 1;
|
char *branch = strrchr(refname, '/') + 1;
|
||||||
const char *remote;
|
|
||||||
|
|
||||||
/* A remote branch of the same name is deemed similar */
|
/* A remote branch of the same name is deemed similar */
|
||||||
if (skip_prefix(refname, "refs/remotes/", &remote) &&
|
if (starts_with(refname, "refs/remotes/") &&
|
||||||
!strcmp(branch, cb->base_ref))
|
!strcmp(branch, cb->base_ref))
|
||||||
string_list_append(cb->similar_refs, remote);
|
string_list_append_nodup(cb->similar_refs,
|
||||||
|
shorten_unambiguous_ref(refname, 1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct string_list guess_refs(const char *ref)
|
static struct string_list guess_refs(const char *ref)
|
||||||
{
|
{
|
||||||
struct similar_ref_cb ref_cb;
|
struct similar_ref_cb ref_cb;
|
||||||
struct string_list similar_refs = STRING_LIST_INIT_NODUP;
|
struct string_list similar_refs = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
ref_cb.base_ref = ref;
|
ref_cb.base_ref = ref;
|
||||||
ref_cb.similar_refs = &similar_refs;
|
ref_cb.similar_refs = &similar_refs;
|
||||||
|
|
|
@ -893,4 +893,24 @@ test_expect_success 'merge --quit' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'merge suggests matching remote refname' '
|
||||||
|
git commit --allow-empty -m not-local &&
|
||||||
|
git update-ref refs/remotes/origin/not-local HEAD &&
|
||||||
|
git reset --hard HEAD^ &&
|
||||||
|
|
||||||
|
# This is white-box testing hackery; we happen to know
|
||||||
|
# that reading packed refs is more picky about the memory
|
||||||
|
# ownership of strings we pass to for_each_ref() callbacks.
|
||||||
|
git pack-refs --all --prune &&
|
||||||
|
|
||||||
|
test_must_fail git merge not-local 2>stderr &&
|
||||||
|
grep origin/not-local stderr
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'suggested names are not ambiguous' '
|
||||||
|
git update-ref refs/heads/origin/not-local HEAD &&
|
||||||
|
test_must_fail git merge not-local 2>stderr &&
|
||||||
|
grep remotes/origin/not-local stderr
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue