@@ -13,24 +13,44 @@ test_expect_success 'setup bare remotes' '
1313 git push parent2 HEAD
1414'
1515
16+ # $1 = local revision
17+ # $2 = remote revision (tested to be equal to the local one)
18+ check_pushed_commit () {
19+ git log -1 --format=' %h %s' " $1 " > expect &&
20+ git --git-dir=repo1 log -1 --format=' %h %s' " $2 " > actual &&
21+ test_cmp expect actual
22+ }
23+
24+ # $1 = push.default value
25+ # $2 = expected target branch for the push
26+ test_push_success () {
27+ git -c push.default=" $1 " push &&
28+ check_pushed_commit HEAD " $2 "
29+ }
30+
31+ # $1 = push.default value
32+ # check that push fails and does not modify any remote branch
33+ test_push_failure () {
34+ git --git-dir=repo1 log --no-walk --format=' %h %s' --all > expect &&
35+ test_must_fail git -c push.default=" $1 " push &&
36+ git --git-dir=repo1 log --no-walk --format=' %h %s' --all > actual &&
37+ test_cmp expect actual
38+ }
39+
1640test_expect_success ' "upstream" pushes to configured upstream' '
1741 git checkout master &&
1842 test_config branch.master.remote parent1 &&
1943 test_config branch.master.merge refs/heads/foo &&
20- test_config push.default upstream &&
2144 test_commit two &&
22- git push &&
23- echo two >expect &&
24- git --git-dir=repo1 log -1 --format=%s foo >actual &&
25- test_cmp expect actual
45+ test_push_success upstream foo
2646'
2747
2848test_expect_success ' "upstream" does not push on unconfigured remote' '
2949 git checkout master &&
3050 test_unconfig branch.master.remote &&
3151 test_config push.default upstream &&
3252 test_commit three &&
33- test_must_fail git push
53+ test_push_failure upstream
3454'
3555
3656test_expect_success ' "upstream" does not push on unconfigured branch' '
@@ -39,7 +59,7 @@ test_expect_success '"upstream" does not push on unconfigured branch' '
3959 test_unconfig branch.master.merge &&
4060 test_config push.default upstream
4161 test_commit four &&
42- test_must_fail git push
62+ test_push_failure upstream
4363'
4464
4565test_expect_success ' "upstream" does not push when remotes do not match' '
0 commit comments