summaryrefslogtreecommitdiff
path: root/t/t5533-push-cas.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t5533-push-cas.sh')
-rwxr-xr-xt/t5533-push-cas.sh137
1 files changed, 137 insertions, 0 deletions
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index 0b0eb1d025..7813e8470e 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -13,6 +13,46 @@ setup_srcdst_basic () {
)
}
+# For tests with "--force-if-includes".
+setup_src_dup_dst () {
+ rm -fr src dup dst &&
+ git init --bare dst &&
+ git clone --no-local dst src &&
+ git clone --no-local dst dup
+ (
+ cd src &&
+ test_commit A &&
+ test_commit B &&
+ test_commit C &&
+ git push origin
+ ) &&
+ (
+ cd dup &&
+ git fetch &&
+ git merge origin/master &&
+ git switch -c branch master~2 &&
+ test_commit D &&
+ test_commit E &&
+ git push origin --all
+ ) &&
+ (
+ cd src &&
+ git switch master &&
+ git fetch --all &&
+ git branch branch --track origin/branch &&
+ git rebase origin/master
+ ) &&
+ (
+ cd dup &&
+ git switch master &&
+ test_commit F &&
+ test_commit G &&
+ git switch branch &&
+ test_commit H &&
+ git push origin --all
+ )
+}
+
test_expect_success setup '
# create template repository
test_commit A &&
@@ -256,4 +296,101 @@ test_expect_success 'background updates of REMOTE can be mitigated with a non-up
)
'
+test_expect_success 'background updates to remote can be mitigated with "--force-if-includes"' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ git ls-remote dst refs/heads/master >expect.master &&
+ git ls-remote dst refs/heads/branch >expect.branch &&
+ (
+ cd src &&
+ git switch branch &&
+ test_commit I &&
+ git switch master &&
+ test_commit J &&
+ git fetch --all &&
+ test_must_fail git push --force-with-lease --force-if-includes --all
+ ) &&
+ git ls-remote dst refs/heads/master >actual.master &&
+ git ls-remote dst refs/heads/branch >actual.branch &&
+ test_cmp expect.master actual.master &&
+ test_cmp expect.branch actual.branch
+'
+
+test_expect_success 'background updates to remote can be mitigated with "push.useForceIfIncludes"' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ git ls-remote dst refs/heads/master >expect.master &&
+ (
+ cd src &&
+ git switch branch &&
+ test_commit I &&
+ git switch master &&
+ test_commit J &&
+ git fetch --all &&
+ git config --local push.useForceIfIncludes true &&
+ test_must_fail git push --force-with-lease=master origin master
+ ) &&
+ git ls-remote dst refs/heads/master >actual.master &&
+ test_cmp expect.master actual.master
+'
+
+test_expect_success '"--force-if-includes" should be disabled for --force-with-lease="<refname>:<expect>"' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ git ls-remote dst refs/heads/master >expect.master &&
+ (
+ cd src &&
+ git switch branch &&
+ test_commit I &&
+ git switch master &&
+ test_commit J &&
+ remote_head="$(git rev-parse refs/remotes/origin/master)" &&
+ git fetch --all &&
+ test_must_fail git push --force-if-includes --force-with-lease="master:$remote_head" 2>err &&
+ grep "stale info" err
+ ) &&
+ git ls-remote dst refs/heads/master >actual.master &&
+ test_cmp expect.master actual.master
+'
+
+test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase")' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git switch branch &&
+ test_commit I &&
+ git switch master &&
+ test_commit J &&
+ git pull --rebase origin master &&
+ git push --force-if-includes --force-with-lease="master"
+ )
+'
+
+test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git switch branch &&
+ test_commit I &&
+ git switch master &&
+ test_commit J &&
+ git pull --rebase origin master &&
+ git rebase --onto HEAD~4 HEAD~1 &&
+ git push --force-if-includes --force-with-lease="master"
+ )
+'
+
+test_expect_success '"--force-if-includes" should allow deletes' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git switch branch &&
+ git pull --rebase origin branch &&
+ git push --force-if-includes --force-with-lease="branch" origin :branch
+ )
+'
+
test_done