From: Jonathan Nieder <jrnieder@gmail.com>
To: Johan Herland <johan@herland.net>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCHv2 1/8] t2024: Add tests verifying current DWIM behavior of 'git checkout <branch>'
Date: Sat, 20 Apr 2013 13:44:50 -0700 [thread overview]
Message-ID: <20130420204449.GC8586@elie.Belkin> (raw)
In-Reply-To: <1366470363-22309-2-git-send-email-johan@herland.net>
Johan Herland wrote:
> The DWIM mode of checkout allows you to run "git checkout foo" when there is
> no existing local ref or path called "foo" and there is exactly one remote
> with a remote-tracking branch called "foo".
Thanks for testing this. I'm surprised no one suggested a test since
v1.7.0-rc0~51^2~6 (2009-10-18).
Maybe it would also be worthwhile to also test --no-guess? (c.f.
46148dd7, 2009-10-18)
[...]
> +++ b/t/t2024-checkout-dwim.sh
> @@ -0,0 +1,66 @@
[...]
> +# Arguments: <branch> <remote> <remote-tracking>
> +#
> +# Verify that we have checked out <branch>, and that it is at the same
> +# commit as <remote-tracking>, and that has appropriate tracking config
> +# setup against <remote>
> +test_tracking_branch() {
> + branch=$1 &&
> + remote=$2 &&
> + remote_track=$3 &&
> + test "refs/heads/$branch" = "$(git rev-parse --symbolic-full-name HEAD)" &&
> + test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify "$remote_track")" &&
> + test "$remote" = "$(git config "branch.$branch.remote")" &&
> + test "refs/heads/$branch" = "$(git config "branch.$branch.merge")"
Stylistic tweaks:
* setting all local vars on one line
* avoiding command substitution so we notice if commands fail
* using test_cmp in place of test $foo = $bar for better output
when the test fails
# Is the current branch "refs/heads/$1"?
test_branch () {
printf "%s\n" "refs/heads/$1" >expect.HEAD &&
git symbolic-ref HEAD >actual.HEAD &&
test_cmp expect.HEAD actual.HEAD
}
# Is branch "refs/heads/$1" set to pull from "$2/$3"?
test_branch_upstream () {
printf "%s\n" "$2" "refs/heads/$3" >expect.upstream &&
{
git config "branch.$1.remote" &&
git config "branch.$1.merge"
} >actual.upstream &&
test_cmp expect.upstream actual.upstream
}
test_tracking_branch () {
branch=$1 remote=$2 remote_branch=$3 &&
test_branch "$branch" &&
test_cmp_rev "refs/remotes/$remote/$remote_branch" HEAD &&
test_branch_upstream "$branch" "$remote" "$remote_branch"
}
> +}
> +
> +test_expect_success 'setup' '
> + (git init repo_a &&
> + cd repo_a &&
> + test_commit a_master &&
> + git checkout -b foo &&
> + test_commit a_foo &&
> + git checkout -b bar &&
> + test_commit a_bar
> + ) &&
> + (git init repo_b &&
> + cd repo_b &&
> + test_commit b_master &&
> + git checkout -b foo &&
> + test_commit b_foo &&
> + git checkout -b baz &&
> + test_commit b_baz
> + ) &&
> + git remote add repo_a repo_a &&
> + git remote add repo_b repo_b &&
> + git config remote.repo_b.fetch \
> + "+refs/heads/*:refs/remotes/other_b/*" &&
> + git fetch --all
Style: indenting code in subshells.
test_expect_success 'setup' '
git init repo_a &&
(
cd repo_a &&
test_commit a_master &&
git checkout -b foo &&
test_commit a_foo &&
git checkout -b bar &&
test_commit a_bar
) &&
git init repo_b &&
(
cd repo_b &&
test_commit b_master &&
git checkout -b foo &&
test_commit b_foo &&
git checkout -b baz &&
test_commit b_baz
) &&
git remote add repo_a repo_a &&
git remote add repo_b repo_b &&
git config remote.repo_b.fetch \
"+refs/heads/*:refs/remotes/other_b/*" &&
git fetch --all
'
> +'
> +
> +test_expect_success 'checkout of non-existing branch fails' '
> + test_must_fail git checkout xyzzy
> +'
Maybe, to defend against state from previous tests and confirm that
the checkout didn't do anything:
git checkout -B master &&
test_might_fail git branch -D xyzzy &&
test_must_fail git checkout xyzzy &&
test_must_fail git rev-parse --verify refs/heads/xyzzy &&
test_branch master
> +
> +test_expect_success 'checkout of branch from multiple remotes fails' '
> + test_must_fail git checkout foo
> +'
Likewise:
git checkout -B master &&
test_might_fail git branch -D foo &&
test_must_fail git checkout foo &&
test_must_fail git rev-parse --verify refs/heads/foo &&
test_branch master
> +
> +test_expect_success 'checkout of branch from a single remote succeeds #1' '
> + git checkout bar &&
> + test_tracking_branch bar repo_a refs/remotes/repo_a/bar
git checkout -B master &&
test_might_fail git branch -D bar &&
git checkout bar &&
test_branch bar &&
test_cmp_rev remotes/repo_a/bar HEAD &&
test_branch_upstream bar repo_a bar
> +test_expect_success 'checkout of branch from a single remote succeeds #2' '
> + git checkout baz &&
> + test_tracking_branch baz repo_b refs/remotes/other_b/baz
git checkout -B master &&
test_might_fail git branch -D baz &&
git checkout baz &&
test_branch baz &&
test_cmp_rev remotes/other_b/baz HEAD &&
test_branch_upstream baz repo_b baz
And for --no-guess:
test_expect_success '--no-guess suppresses branch auto-vivification' '
git checkout -B master &&
test_might_fail git branch -D bar &&
test_must_fail git checkout --no-guess bar &&
test_must_fail git rev-parse --verify refs/heads/bar &&
test_branch master
'
Sane?
Thanks,
Jonathan
next prev parent reply other threads:[~2013-04-20 20:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-20 15:05 [PATCHv2 0/8] Improving the search for remote-tracking branches Johan Herland
2013-04-20 15:05 ` [PATCHv2 1/8] t2024: Add tests verifying current DWIM behavior of 'git checkout <branch>' Johan Herland
2013-04-20 20:44 ` Jonathan Nieder [this message]
2013-04-20 22:53 ` Johan Herland
2013-04-20 15:05 ` [PATCHv2 2/8] t2024: Show failure to use refspec when DWIMming remote branch names Johan Herland
2013-04-20 15:05 ` [PATCHv2 3/8] checkout: Use remote refspecs when DWIMming tracking branches Johan Herland
2013-04-20 15:05 ` [PATCHv2 4/8] t3200.39: tracking setup should fail if there is no matching refspec Johan Herland
2013-04-20 15:06 ` [PATCHv2 5/8] t7201.24: Add refspec to keep --track working Johan Herland
2013-04-20 15:06 ` [PATCHv2 6/8] t9114.2: Don't use --track option against "svn-remote"-tracking branches Johan Herland
2013-04-21 5:24 ` Eric Wong
2013-04-20 15:06 ` [PATCHv2 7/8] branch.c: Validate tracking branches with refspecs instead of refs/remotes/* Johan Herland
2013-04-20 15:06 ` [PATCHv2 8/8] glossary: Update and rephrase the definition of a remote-tracking branch Johan Herland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130420204449.GC8586@elie.Belkin \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johan@herland.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).