From 1b4aee94aaffd5e6fdf3020434b3fa6f0c5cfb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Apr 2012 09:54:31 +0200 Subject: t1507: add tests to document @{upstream} behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In preparation for future changes, add tests which show error messages with @{upstream} in various conditions: - test branch@{u} with . as remote - check error message for branch@{u} on a branch with * no upstream, * on a branch with a configured upstream which doesn't have a remote-tracking branch - check error message for branch@{u} when branch 'branch' does not exist - check error message for @{u} without the branch name Right now the messages are very similar, but various cases can and will be distinguished. Note: test_i18ncmp is not used, because currently error output is not internationalized. test_cmp will be switched to test_i18ncmp in a later patch, when error messages are internationalized. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- t/t1507-rev-parse-upstream.sh | 81 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index a4555510c3..c4981ba407 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -15,10 +15,18 @@ test_expect_success 'setup' ' test_commit 3 && (cd clone && test_commit 4 && - git branch --track my-side origin/side) - + git branch --track my-side origin/side && + git branch --track local-master master && + git remote add -t master master-only .. && + git fetch master-only && + git branch bad-upstream && + git config branch.bad-upstream.remote master-only && + git config branch.bad-upstream.merge refs/heads/side + ) ' +sq="'" + full_name () { (cd clone && git rev-parse --symbolic-full-name "$@") @@ -29,6 +37,11 @@ commit_subject () { git show -s --pretty=format:%s "$@") } +error_message () { + (cd clone && + test_must_fail git rev-parse --verify "$@") +} + test_expect_success '@{upstream} resolves to correct full name' ' test refs/remotes/origin/master = "$(full_name @{upstream})" ' @@ -78,7 +91,6 @@ test_expect_success 'checkout -b new my-side@{u} forks from the same' ' test_expect_success 'merge my-side@{u} records the correct name' ' ( - sq="'\''" && cd clone || exit git checkout master || exit git branch -D new ;# can fail but is ok @@ -107,6 +119,69 @@ test_expect_success 'checkout other@{u}' ' test_cmp expect actual ' +test_expect_success 'branch@{u} works when tracking a local branch' ' + test refs/heads/master = "$(full_name local-master@{u})" +' + +test_expect_success 'branch@{u} error message when no upstream' ' + cat >expect <<-EOF && + error: No upstream branch found for ${sq}non-tracking${sq} + fatal: Needed a single revision + EOF + error_message non-tracking@{u} 2>actual && + test_cmp expect actual +' + +test_expect_success '@{u} error message when no upstream' ' + cat >expect <<-EOF && + error: No upstream branch found for ${sq}${sq} + fatal: Needed a single revision + EOF + test_must_fail git rev-parse --verify @{u} 2>actual && + test_cmp expect actual +' + +test_expect_success 'branch@{u} error message with misspelt branch' ' + cat >expect <<-EOF && + error: No upstream branch found for ${sq}no-such-branch${sq} + fatal: Needed a single revision + EOF + error_message no-such-branch@{u} 2>actual && + test_cmp expect actual +' + +test_expect_success '@{u} error message when not on a branch' ' + cat >expect <<-EOF && + error: No upstream branch found for ${sq}${sq} + fatal: Needed a single revision + EOF + git checkout HEAD^0 && + test_must_fail git rev-parse --verify @{u} 2>actual && + test_cmp expect actual +' + +test_expect_success 'branch@{u} error message if upstream branch not fetched' ' + cat >expect <<-EOF && + error: No upstream branch found for ${sq}bad-upstream${sq} + fatal: Needed a single revision + EOF + error_message bad-upstream@{u} 2>actual && + test_cmp expect actual +' + +test_expect_success 'pull works when tracking a local branch' ' +( + cd clone && + git checkout local-master && + git pull +) +' + +# makes sense if the previous one succeeded +test_expect_success '@{u} works when tracking a local branch' ' + test refs/heads/master = "$(full_name @{u})" +' + cat >expect <) -- cgit v1.2.3 From 9884e67f9d9b511592b981572cfbb30cc50aec61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Apr 2012 09:54:32 +0200 Subject: Provide branch name in error message when using @{u} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using @{u} or @{upstream} it is common to omit the branch name, implying current branch. If the upstream is not configured, the error message was "No upstream branch found for ''". When resolving '@{u}', branch_get() is called, which almost always returns a description of a branch. This allows us to use a branch name in the error message, even if the user said something like '@{u}'. The only case when branch_get() returns NULL is when HEAD points to so something which is not a branch. Of course this also means that no upstream is configured, but it is better to directly say that HEAD does not point to a branch. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- sha1_name.c | 12 ++++++++---- t/t1507-rev-parse-upstream.sh | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 03ffc2caaa..c2fe1aae52 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -856,10 +856,14 @@ int interpret_branch_name(const char *name, struct strbuf *buf) len = cp + tmp_len - name; cp = xstrndup(name, cp - name); upstream = branch_get(*cp ? cp : NULL); - if (!upstream - || !upstream->merge - || !upstream->merge[0]->dst) - return error("No upstream branch found for '%s'", cp); + /* + * Upstream can be NULL only if cp refers to HEAD and HEAD + * points to something different than a branch. + */ + if (!upstream) + return error("HEAD does not point to a branch"); + if (!upstream->merge || !upstream->merge[0]->dst) + return error("No upstream branch found for '%s'", upstream->name); free(cp); cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0); strbuf_reset(buf); diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index c4981ba407..2f4f0d1c02 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -134,7 +134,7 @@ test_expect_success 'branch@{u} error message when no upstream' ' test_expect_success '@{u} error message when no upstream' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}${sq} + error: No upstream branch found for ${sq}master${sq} fatal: Needed a single revision EOF test_must_fail git rev-parse --verify @{u} 2>actual && @@ -152,7 +152,7 @@ test_expect_success 'branch@{u} error message with misspelt branch' ' test_expect_success '@{u} error message when not on a branch' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}${sq} + error: HEAD does not point to a branch fatal: Needed a single revision EOF git checkout HEAD^0 && -- cgit v1.2.3 From bb0dab5d617219d7efe8815cadef6d98c4bc3df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Apr 2012 09:54:33 +0200 Subject: Provide better message for barnhc_wiht_tpyo@{u} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of just saying that no upstream exists for such branch, which is true but not very helpful, check that there's no refs/heads/barnhc_wiht_tpyo and tell it to the user. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- sha1_name.c | 5 ++++- t/t1507-rev-parse-upstream.sh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index c2fe1aae52..e2d576ad7b 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -862,8 +862,11 @@ int interpret_branch_name(const char *name, struct strbuf *buf) */ if (!upstream) return error("HEAD does not point to a branch"); - if (!upstream->merge || !upstream->merge[0]->dst) + if (!upstream->merge || !upstream->merge[0]->dst) { + if (!ref_exists(upstream->refname)) + return error("No such branch: '%s'", cp); return error("No upstream branch found for '%s'", upstream->name); + } free(cp); cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0); strbuf_reset(buf); diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 2f4f0d1c02..2b8ba314a9 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -143,7 +143,7 @@ test_expect_success '@{u} error message when no upstream' ' test_expect_success 'branch@{u} error message with misspelt branch' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}no-such-branch${sq} + error: No such branch: ${sq}no-such-branch${sq} fatal: Needed a single revision EOF error_message no-such-branch@{u} 2>actual && -- cgit v1.2.3 From 17c82211ec2d29a6e7221948cba8dae9074dc5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Apr 2012 09:54:34 +0200 Subject: Be more specific if upstream branch is not tracked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the branch configured as upstream didn't have a local tracking branch, git said "Upstream branch not found". We can be more helpful, and separate the cases when upstream is not configured, and when it is configured, but the upstream branch is not tracked in a local branch. The following configuration leads to the second scenario: [remote "origin"] url = ... fetch = refs/heads/master [branch "master"] remote = origin merge = refs/heads/master 'git pull' will work on master, but master@{upstream} is not defined. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- sha1_name.c | 7 ++++++- t/t1507-rev-parse-upstream.sh | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index e2d576ad7b..361708b7bb 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -865,7 +865,12 @@ int interpret_branch_name(const char *name, struct strbuf *buf) if (!upstream->merge || !upstream->merge[0]->dst) { if (!ref_exists(upstream->refname)) return error("No such branch: '%s'", cp); - return error("No upstream branch found for '%s'", upstream->name); + if (!upstream->merge) + return error("No upstream configured for branch '%s'", + upstream->name); + return error( + "Upstream branch '%s' not stored as a remote-tracking branch", + upstream->merge[0]->src); } free(cp); cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0); diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 2b8ba314a9..e742ce0332 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -125,7 +125,7 @@ test_expect_success 'branch@{u} works when tracking a local branch' ' test_expect_success 'branch@{u} error message when no upstream' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}non-tracking${sq} + error: No upstream configured for branch ${sq}non-tracking${sq} fatal: Needed a single revision EOF error_message non-tracking@{u} 2>actual && @@ -134,7 +134,7 @@ test_expect_success 'branch@{u} error message when no upstream' ' test_expect_success '@{u} error message when no upstream' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}master${sq} + error: No upstream configured for branch ${sq}master${sq} fatal: Needed a single revision EOF test_must_fail git rev-parse --verify @{u} 2>actual && @@ -162,7 +162,7 @@ test_expect_success '@{u} error message when not on a branch' ' test_expect_success 'branch@{u} error message if upstream branch not fetched' ' cat >expect <<-EOF && - error: No upstream branch found for ${sq}bad-upstream${sq} + error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch fatal: Needed a single revision EOF error_message bad-upstream@{u} 2>actual && -- cgit v1.2.3 From 647202889397e775c294234ebd3df8b2c4473f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 14 Apr 2012 09:54:35 +0200 Subject: i18n: mark @{upstream} error messages for translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- sha1_name.c | 8 ++++---- t/t1507-rev-parse-upstream.sh | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 361708b7bb..c6331136d1 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -861,15 +861,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf) * points to something different than a branch. */ if (!upstream) - return error("HEAD does not point to a branch"); + return error(_("HEAD does not point to a branch")); if (!upstream->merge || !upstream->merge[0]->dst) { if (!ref_exists(upstream->refname)) - return error("No such branch: '%s'", cp); + return error(_("No such branch: '%s'"), cp); if (!upstream->merge) - return error("No upstream configured for branch '%s'", + return error(_("No upstream configured for branch '%s'"), upstream->name); return error( - "Upstream branch '%s' not stored as a remote-tracking branch", + _("Upstream branch '%s' not stored as a remote-tracking branch"), upstream->merge[0]->src); } free(cp); diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index e742ce0332..d6e576192f 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -129,7 +129,7 @@ test_expect_success 'branch@{u} error message when no upstream' ' fatal: Needed a single revision EOF error_message non-tracking@{u} 2>actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_expect_success '@{u} error message when no upstream' ' @@ -138,7 +138,7 @@ test_expect_success '@{u} error message when no upstream' ' fatal: Needed a single revision EOF test_must_fail git rev-parse --verify @{u} 2>actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_expect_success 'branch@{u} error message with misspelt branch' ' @@ -147,7 +147,7 @@ test_expect_success 'branch@{u} error message with misspelt branch' ' fatal: Needed a single revision EOF error_message no-such-branch@{u} 2>actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_expect_success '@{u} error message when not on a branch' ' @@ -157,7 +157,7 @@ test_expect_success '@{u} error message when not on a branch' ' EOF git checkout HEAD^0 && test_must_fail git rev-parse --verify @{u} 2>actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_expect_success 'branch@{u} error message if upstream branch not fetched' ' @@ -166,7 +166,7 @@ test_expect_success 'branch@{u} error message if upstream branch not fetched' ' fatal: Needed a single revision EOF error_message bad-upstream@{u} 2>actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_expect_success 'pull works when tracking a local branch' ' -- cgit v1.2.3