Imported Upstream version 2.27.0
[platform/upstream/git.git] / t / t1400-update-ref.sh
index a6224ef..e1197ac 100755 (executable)
@@ -1354,15 +1354,6 @@ test_expect_success 'fails with duplicate ref update via symref' '
        test_cmp expect actual
 '
 
-run_with_limited_open_files () {
-       (ulimit -n 32 && "$@")
-}
-
-test_lazy_prereq ULIMIT_FILE_DESCRIPTORS '
-       test_have_prereq !MINGW,!CYGWIN &&
-       run_with_limited_open_files true
-'
-
 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
 (
        for i in $(test_seq 33)
@@ -1404,4 +1395,135 @@ test_expect_success 'handle per-worktree refs in refs/bisect' '
        ! test_cmp main-head worktree-head
 '
 
+test_expect_success 'transaction handles empty commit' '
+       cat >stdin <<-EOF &&
+       start
+       prepare
+       commit
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start prepare commit >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction handles empty commit with missing prepare' '
+       cat >stdin <<-EOF &&
+       start
+       commit
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start commit >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction handles sole commit' '
+       cat >stdin <<-EOF &&
+       commit
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" commit >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction handles empty abort' '
+       cat >stdin <<-EOF &&
+       start
+       prepare
+       abort
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start prepare abort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction exits on multiple aborts' '
+       cat >stdin <<-EOF &&
+       abort
+       abort
+       EOF
+       test_must_fail git update-ref --stdin <stdin >actual 2>err &&
+       printf "%s: ok\n" abort >expect &&
+       test_cmp expect actual &&
+       grep "fatal: transaction is closed" err
+'
+
+test_expect_success 'transaction exits on start after prepare' '
+       cat >stdin <<-EOF &&
+       prepare
+       start
+       EOF
+       test_must_fail git update-ref --stdin <stdin 2>err >actual &&
+       printf "%s: ok\n" prepare >expect &&
+       test_cmp expect actual &&
+       grep "fatal: prepared transactions can only be closed" err
+'
+
+test_expect_success 'transaction handles empty abort with missing prepare' '
+       cat >stdin <<-EOF &&
+       start
+       abort
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start abort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction handles sole abort' '
+       cat >stdin <<-EOF &&
+       abort
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" abort >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction can handle commit' '
+       cat >stdin <<-EOF &&
+       start
+       create $a HEAD
+       commit
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start commit >expect &&
+       test_cmp expect actual &&
+       git rev-parse HEAD >expect &&
+       git rev-parse $a >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'transaction can handle abort' '
+       cat >stdin <<-EOF &&
+       start
+       create $b HEAD
+       abort
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start abort >expect &&
+       test_cmp expect actual &&
+       test_path_is_missing .git/$b
+'
+
+test_expect_success 'transaction aborts by default' '
+       cat >stdin <<-EOF &&
+       start
+       create $b HEAD
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start >expect &&
+       test_cmp expect actual &&
+       test_path_is_missing .git/$b
+'
+
+test_expect_success 'transaction with prepare aborts by default' '
+       cat >stdin <<-EOF &&
+       start
+       create $b HEAD
+       prepare
+       EOF
+       git update-ref --stdin <stdin >actual &&
+       printf "%s: ok\n" start prepare >expect &&
+       test_cmp expect actual &&
+       test_path_is_missing .git/$b
+'
+
 test_done