t5528-push-default.sh: add helper functions
[git.git] / t / t5528-push-default.sh
blob99e551926367daf652ec1eb0bd917c7470097e42
1 #!/bin/sh
3 test_description='check various push.default settings'
4 . ./test-lib.sh
6 test_expect_success 'setup bare remotes' '
7 git init --bare repo1 &&
8 git remote add parent1 repo1 &&
9 git init --bare repo2 &&
10 git remote add parent2 repo2 &&
11 test_commit one &&
12 git push parent1 HEAD &&
13 git push parent2 HEAD
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
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"
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
40 test_expect_success '"upstream" pushes to configured upstream' '
41 git checkout master &&
42 test_config branch.master.remote parent1 &&
43 test_config branch.master.merge refs/heads/foo &&
44 test_commit two &&
45 test_push_success upstream foo
48 test_expect_success '"upstream" does not push on unconfigured remote' '
49 git checkout master &&
50 test_unconfig branch.master.remote &&
51 test_config push.default upstream &&
52 test_commit three &&
53 test_push_failure upstream
56 test_expect_success '"upstream" does not push on unconfigured branch' '
57 git checkout master &&
58 test_config branch.master.remote parent1 &&
59 test_unconfig branch.master.merge &&
60 test_config push.default upstream
61 test_commit four &&
62 test_push_failure upstream
65 test_expect_success '"upstream" does not push when remotes do not match' '
66 git checkout master &&
67 test_config branch.master.remote parent1 &&
68 test_config branch.master.merge refs/heads/foo &&
69 test_config push.default upstream &&
70 test_commit five &&
71 test_must_fail git push parent2
74 test_done