t3428: modernize test setup

Perform the setup in a dedicated test so the later tests can be run independently. Also avoid running git upstream of a pipe and take advantage of test_commit. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Apr 9, 2024 at 15:27 UTC aac1c6e8f5e0a2dd8c9e897b56d8860fbf235dfb
1 file changed +21 -21
t/t3428-rebase-signoff.sh
+21 -21
@@ -8,37 +8,37 @@ This test runs git rebase --signoff and make sure that it works.
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 -# A simple file to commit
12 -cat >file <<EOF
13 -a
14 -EOF
11 +test_expect_success 'setup' '
12 + git commit --allow-empty -m "Initial empty commit" &&
13 + test_commit first file a &&
14 +
15 + ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
16
16 -# Expected commit message for initial commit after rebase --signoff
17 -cat >expected-initial-signed <<EOF
18 -Initial empty commit
17 + # Expected commit message for initial commit after rebase --signoff
18 + cat >expected-initial-signed <<-EOF &&
19 + Initial empty commit
20
20 -Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
21 -EOF
21 + Signed-off-by: $ident
22 + EOF
23
23 -# Expected commit message after rebase --signoff
24 -cat >expected-signed <<EOF
25 -first
24 + # Expected commit message after rebase --signoff
25 + cat >expected-signed <<-EOF &&
26 + first
27
27 -Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
28 -EOF
28 + Signed-off-by: $ident
29 + EOF
30
30 -# Expected commit message after rebase without --signoff (or with --no-signoff)
31 -cat >expected-unsigned <<EOF
32 -first
33 -EOF
31 + # Expected commit message after rebase without --signoff (or with --no-signoff)
32 + cat >expected-unsigned <<-EOF &&
33 + first
34 + EOF
35
36 + git config alias.rbs "rebase --signoff"
37 +'
38
39 # We configure an alias to do the rebase --signoff so that
40 # on the next subtest we can show that --no-signoff overrides the alias
41 test_expect_success 'rebase --signoff adds a sign-off line' '
39 - git commit --allow-empty -m "Initial empty commit" &&
40 - git add file && git commit -m first &&
41 - git config alias.rbs "rebase --signoff" &&
42 git rbs HEAD^ &&
43 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
44 test_cmp expected-signed actual