]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5528-push-default.sh
t/t5528-push-default: generalize test_push_*
[thirdparty/git.git] / t / t5528-push-default.sh
CommitLineData
135dadef
JH
1#!/bin/sh
2
3test_description='check various push.default settings'
4. ./test-lib.sh
5
6test_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
14'
15
321e75c5
MM
16# $1 = local revision
17# $2 = remote revision (tested to be equal to the local one)
396243fa 18# $3 = [optional] repo to check for actual output (repo1 by default)
321e75c5
MM
19check_pushed_commit () {
20 git log -1 --format='%h %s' "$1" >expect &&
396243fa 21 git --git-dir="${3:-repo1}" log -1 --format='%h %s' "$2" >actual &&
321e75c5
MM
22 test_cmp expect actual
23}
24
25# $1 = push.default value
26# $2 = expected target branch for the push
396243fa 27# $3 = [optional] repo to check for actual output (repo1 by default)
321e75c5
MM
28test_push_success () {
29 git -c push.default="$1" push &&
396243fa 30 check_pushed_commit HEAD "$2" "$3"
321e75c5
MM
31}
32
33# $1 = push.default value
34# check that push fails and does not modify any remote branch
35test_push_failure () {
36 git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect &&
37 test_must_fail git -c push.default="$1" push &&
38 git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual &&
39 test_cmp expect actual
40}
41
135dadef
JH
42test_expect_success '"upstream" pushes to configured upstream' '
43 git checkout master &&
44 test_config branch.master.remote parent1 &&
45 test_config branch.master.merge refs/heads/foo &&
135dadef 46 test_commit two &&
321e75c5 47 test_push_success upstream foo
135dadef
JH
48'
49
50test_expect_success '"upstream" does not push on unconfigured remote' '
51 git checkout master &&
52 test_unconfig branch.master.remote &&
135dadef 53 test_commit three &&
321e75c5 54 test_push_failure upstream
135dadef
JH
55'
56
57test_expect_success '"upstream" does not push on unconfigured branch' '
58 git checkout master &&
59 test_config branch.master.remote parent1 &&
60 test_unconfig branch.master.merge &&
135dadef 61 test_commit four &&
321e75c5 62 test_push_failure upstream
135dadef
JH
63'
64
65test_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
72'
73
b55e6775
MM
74test_expect_success 'push from/to new branch with upstream, matching and simple' '
75 git checkout -b new-branch &&
76 test_push_failure simple &&
77 test_push_failure matching &&
78 test_push_failure upstream
79'
80
81test_expect_success 'push from/to new branch with current creates remote branch' '
82 test_config branch.new-branch.remote repo1 &&
83 git checkout new-branch &&
84 test_push_success current new-branch
85'
86
87test_expect_success 'push to existing branch, with no upstream configured' '
88 test_config branch.master.remote repo1 &&
89 git checkout master &&
90 test_push_failure simple &&
91 test_push_failure upstream
92'
93
94test_expect_success 'push to existing branch, upstream configured with same name' '
95 test_config branch.master.remote repo1 &&
96 test_config branch.master.merge refs/heads/master &&
97 git checkout master &&
98 test_commit six &&
99 test_push_success upstream master &&
100 test_commit seven &&
101 test_push_success simple master
102'
103
104test_expect_success 'push to existing branch, upstream configured with different name' '
105 test_config branch.master.remote repo1 &&
106 test_config branch.master.merge refs/heads/other-name &&
107 git checkout master &&
108 test_commit eight &&
109 test_push_success upstream other-name &&
110 test_commit nine &&
111 test_push_failure simple &&
112 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >expect-other-name &&
113 test_push_success current master &&
114 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >actual-other-name &&
115 test_cmp expect-other-name actual-other-name
116'
117
135dadef 118test_done