Skip to content

Commit

Permalink
t5528-push-default.sh: add helper functions
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Matthieu Moy authored and Junio C Hamano committed Apr 24, 2012
1 parent 628ab0e commit 321e75c
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions t/t5528-push-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,44 @@ test_expect_success 'setup bare remotes' '
git push parent2 HEAD
'

# $1 = local revision
# $2 = remote revision (tested to be equal to the local one)
check_pushed_commit () {
git log -1 --format='%h %s' "$1" >expect &&
git --git-dir=repo1 log -1 --format='%h %s' "$2" >actual &&
test_cmp expect actual
}

# $1 = push.default value
# $2 = expected target branch for the push
test_push_success () {
git -c push.default="$1" push &&
check_pushed_commit HEAD "$2"
}

# $1 = push.default value
# check that push fails and does not modify any remote branch
test_push_failure () {
git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect &&
test_must_fail git -c push.default="$1" push &&
git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual &&
test_cmp expect actual
}

test_expect_success '"upstream" pushes to configured upstream' '
git checkout master &&
test_config branch.master.remote parent1 &&
test_config branch.master.merge refs/heads/foo &&
test_config push.default upstream &&
test_commit two &&
git push &&
echo two >expect &&
git --git-dir=repo1 log -1 --format=%s foo >actual &&
test_cmp expect actual
test_push_success upstream foo
'

test_expect_success '"upstream" does not push on unconfigured remote' '
git checkout master &&
test_unconfig branch.master.remote &&
test_config push.default upstream &&
test_commit three &&
test_must_fail git push
test_push_failure upstream
'

test_expect_success '"upstream" does not push on unconfigured branch' '
Expand All @@ -39,7 +59,7 @@ test_expect_success '"upstream" does not push on unconfigured branch' '
test_unconfig branch.master.merge &&
test_config push.default upstream
test_commit four &&
test_must_fail git push
test_push_failure upstream
'

test_expect_success '"upstream" does not push when remotes do not match' '
Expand Down

0 comments on commit 321e75c

Please sign in to comment.