Felipe Contreras <felipe.contre...@gmail.com> writes:

> After every test the environment should be as close as to how it was
> before as possible.

Alternatively, each individual tests in a sequence of tests can
choose to set the test environment to its preferred state before
proceeding.  

Starting from a pristine state (i.e. the goal the above aspires to
reach) is probably more desirable, but in practice we could go
either way.  In any case we should consistently stick to one inside
a single test.

> Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
> ---
>  t/t3200-branch.sh | 71 
> +++++++++++++++++++++++++++----------------------------
>  1 file changed, 35 insertions(+), 36 deletions(-)
>
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 0fe7647..33673e0 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -329,7 +329,7 @@ test_expect_success 'tracking setup fails on non-matching 
> refspec' '
>  '
>  
>  test_expect_success 'test tracking setup via config' '
> -     git config branch.autosetupmerge true &&
> +     test_config branch.autosetupmerge true &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&

And "remote.local.*" setting does not follow that "pristine"
principle, making the result of applying this patch inconsistent.
Is that desirable?



>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -339,20 +339,18 @@ test_expect_success 'test tracking setup via config' '
>  '
>  
>  test_expect_success 'test overriding tracking setup via --no-track' '
> -     git config branch.autosetupmerge true &&
> +     test_config branch.autosetupmerge true &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
>       git branch --no-track my2 local/master &&
> -     git config branch.autosetupmerge false &&
>       ! test "$(git config branch.my2.remote)" = local &&
>       ! test "$(git config branch.my2.merge)" = refs/heads/master
>  '
>  
>  test_expect_success 'no tracking without .fetch entries' '
> -     git config branch.autosetupmerge true &&
> +     test_config branch.autosetupmerge true &&
>       git branch my6 s &&
> -     git config branch.autosetupmerge false &&
>       test -z "$(git config branch.my6.remote)" &&
>       test -z "$(git config branch.my6.merge)"
>  '
> @@ -387,9 +385,8 @@ test_expect_success 'test --track without .fetch entries' 
> '
>  '
>  
>  test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
> -     git config branch.autosetupmerge always &&
> -     git branch my9 HEAD^ &&
> -     git config branch.autosetupmerge false
> +     test_config branch.autosetupmerge always &&
> +     git branch my9 HEAD^
>  '
>  
>  test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
> @@ -406,9 +403,9 @@ test_expect_success '--set-upstream-to fails on multiple 
> branches' '
>  '
>  
>  test_expect_success '--set-upstream-to fails on detached HEAD' '
> +     test_when_finished "git checkout -" &&
>       git checkout HEAD^{} &&
> -     test_must_fail git branch --set-upstream-to master &&
> -     git checkout -
> +     test_must_fail git branch --set-upstream-to master
>  '
>  
>  test_expect_success '--set-upstream-to fails on a missing dst branch' '
> @@ -460,9 +457,9 @@ test_expect_success '--unset-upstream should fail on 
> multiple branches' '
>  '
>  
>  test_expect_success '--unset-upstream should fail on detached HEAD' '
> +     test_when_finished "git checkout -" &&
>       git checkout HEAD^{} &&
> -     test_must_fail git branch --unset-upstream &&
> -     git checkout -
> +     test_must_fail git branch --unset-upstream
>  '
>  
>  test_expect_success 'test --unset-upstream on a particular branch' '
> @@ -541,7 +538,8 @@ test_expect_success 'checkout -b with -l makes reflog 
> when core.logAllRefUpdates
>  '
>  
>  test_expect_success 'avoid ambiguous track' '
> -     git config branch.autosetupmerge true &&
> +     test_when_finished "git remote rm ambi1 && git remote rm ambi2" &&
> +     test_config branch.autosetupmerge true &&
>       git config remote.ambi1.url lalala &&
>       git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
>       git config remote.ambi2.url lilili &&
> @@ -553,7 +551,7 @@ test_expect_success 'avoid ambiguous track' '
>  test_expect_success 'autosetuprebase local on a tracked local branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase local &&
> +     test_config branch.autosetuprebase local &&
>       (git show-ref -q refs/remotes/local/o || git fetch local) &&
>       git branch mybase &&
>       git branch --track myr1 mybase &&
> @@ -565,7 +563,7 @@ test_expect_success 'autosetuprebase local on a tracked 
> local branch' '
>  test_expect_success 'autosetuprebase always on a tracked local branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase always &&
> +     test_config branch.autosetuprebase always &&
>       (git show-ref -q refs/remotes/local/o || git fetch local) &&
>       git branch mybase2 &&
>       git branch --track myr2 mybase &&
> @@ -577,7 +575,7 @@ test_expect_success 'autosetuprebase always on a tracked 
> local branch' '
>  test_expect_success 'autosetuprebase remote on a tracked local branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase remote &&
> +     test_config branch.autosetuprebase remote &&
>       (git show-ref -q refs/remotes/local/o || git fetch local) &&
>       git branch mybase3 &&
>       git branch --track myr3 mybase2 &&
> @@ -589,7 +587,7 @@ test_expect_success 'autosetuprebase remote on a tracked 
> local branch' '
>  test_expect_success 'autosetuprebase never on a tracked local branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase never &&
> +     test_config branch.autosetuprebase never &&
>       (git show-ref -q refs/remotes/local/o || git fetch local) &&
>       git branch mybase4 &&
>       git branch --track myr4 mybase2 &&
> @@ -601,7 +599,7 @@ test_expect_success 'autosetuprebase never on a tracked 
> local branch' '
>  test_expect_success 'autosetuprebase local on a tracked remote branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase local &&
> +     test_config branch.autosetuprebase local &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
>       git branch --track myr5 local/master &&
>       test "$(git config branch.myr5.remote)" = local &&
> @@ -612,7 +610,7 @@ test_expect_success 'autosetuprebase local on a tracked 
> remote branch' '
>  test_expect_success 'autosetuprebase never on a tracked remote branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase never &&
> +     test_config branch.autosetuprebase never &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
>       git branch --track myr6 local/master &&
>       test "$(git config branch.myr6.remote)" = local &&
> @@ -623,7 +621,7 @@ test_expect_success 'autosetuprebase never on a tracked 
> remote branch' '
>  test_expect_success 'autosetuprebase remote on a tracked remote branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase remote &&
> +     test_config branch.autosetuprebase remote &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
>       git branch --track myr7 local/master &&
>       test "$(git config branch.myr7.remote)" = local &&
> @@ -634,7 +632,7 @@ test_expect_success 'autosetuprebase remote on a tracked 
> remote branch' '
>  test_expect_success 'autosetuprebase always on a tracked remote branch' '
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
> -     git config branch.autosetuprebase remote &&
> +     test_config branch.autosetuprebase remote &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
>       git branch --track myr8 local/master &&
>       test "$(git config branch.myr8.remote)" = local &&
> @@ -643,7 +641,7 @@ test_expect_success 'autosetuprebase always on a tracked 
> remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase unconfigured on a tracked remote 
> branch' '
> -     git config --unset branch.autosetuprebase &&
> +     test_unconfig branch.autosetuprebase &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -685,7 +683,7 @@ test_expect_success 'autosetuprebase unconfigured on 
> untracked remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase never on an untracked local branch' '
> -     git config branch.autosetuprebase never &&
> +     test_config branch.autosetuprebase never &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -696,7 +694,7 @@ test_expect_success 'autosetuprebase never on an 
> untracked local branch' '
>  '
>  
>  test_expect_success 'autosetuprebase local on an untracked local branch' '
> -     git config branch.autosetuprebase local &&
> +     test_config branch.autosetuprebase local &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -707,7 +705,7 @@ test_expect_success 'autosetuprebase local on an 
> untracked local branch' '
>  '
>  
>  test_expect_success 'autosetuprebase remote on an untracked local branch' '
> -     git config branch.autosetuprebase remote &&
> +     test_config branch.autosetuprebase remote &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -718,7 +716,7 @@ test_expect_success 'autosetuprebase remote on an 
> untracked local branch' '
>  '
>  
>  test_expect_success 'autosetuprebase always on an untracked local branch' '
> -     git config branch.autosetuprebase always &&
> +     test_config branch.autosetuprebase always &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -729,7 +727,7 @@ test_expect_success 'autosetuprebase always on an 
> untracked local branch' '
>  '
>  
>  test_expect_success 'autosetuprebase never on an untracked remote branch' '
> -     git config branch.autosetuprebase never &&
> +     test_config branch.autosetuprebase never &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -740,7 +738,7 @@ test_expect_success 'autosetuprebase never on an 
> untracked remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase local on an untracked remote branch' '
> -     git config branch.autosetuprebase local &&
> +     test_config branch.autosetuprebase local &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -751,7 +749,7 @@ test_expect_success 'autosetuprebase local on an 
> untracked remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase remote on an untracked remote branch' '
> -     git config branch.autosetuprebase remote &&
> +     test_config branch.autosetuprebase remote &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -762,7 +760,7 @@ test_expect_success 'autosetuprebase remote on an 
> untracked remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase always on an untracked remote branch' '
> -     git config branch.autosetuprebase always &&
> +     test_config branch.autosetuprebase always &&
>       git config remote.local.url . &&
>       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>       (git show-ref -q refs/remotes/local/master || git fetch local) &&
> @@ -773,8 +771,8 @@ test_expect_success 'autosetuprebase always on an 
> untracked remote branch' '
>  '
>  
>  test_expect_success 'autosetuprebase always on detached HEAD' '
> -     git config branch.autosetupmerge always &&
> -     test_when_finished git checkout master &&
> +     test_when_finished "git checkout -" &&
> +     test_config branch.autosetupmerge always &&
>       git checkout HEAD^0 &&
>       git branch my11 &&
>       test -z "$(git config branch.my11.remote)" &&
> @@ -782,15 +780,15 @@ test_expect_success 'autosetuprebase always on detached 
> HEAD' '
>  '
>  
>  test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
> -     git config branch.autosetuprebase garbage &&
> +     test_config branch.autosetuprebase garbage &&
>       test_must_fail git branch
>  '
>  
>  test_expect_success 'detect misconfigured autosetuprebase (no value)' '
> -     git config --unset branch.autosetuprebase &&
> +     test_when_finished "test_unconfig branch.autosetuprebase" &&
> +     test_unconfig branch.autosetuprebase &&
>       echo "[branch] autosetuprebase" >>.git/config &&
> -     test_must_fail git branch &&
> -     git config --unset branch.autosetuprebase
> +     test_must_fail git branch
>  '
>  
>  test_expect_success 'attempt to delete a branch without base and unmerged to 
> HEAD' '
> @@ -857,6 +855,7 @@ test_expect_success 'detect typo in branch name when 
> using --edit-description' '
>  '
>  
>  test_expect_success 'refuse --edit-description on unborn branch for now' '
> +     test_when_finished "git checkout -" &&
>       write_script editor <<-\EOF &&
>               echo "New contents" >"$1"
>       EOF
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to