Skip to content

Commit d7ef036

Browse files
avargitster
authored andcommitted
gc + p4 tests: use "test_hook", remove sub-shells
Refactor the repository setup code for tests that test hooks the use of sub-shells when setting up the test repository and hooks, and use the "test_hook" wrapper instead of "write_scripts". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f818f7f commit d7ef036

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

t/t6500-gc.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
101101
EOF
102102
103103
git init pre-auto-gc-hook &&
104+
test_hook -C pre-auto-gc-hook pre-auto-gc <<-\EOF &&
105+
echo >&2 no gc for you &&
106+
exit 1
107+
EOF
104108
(
105109
cd pre-auto-gc-hook &&
106-
write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
107-
echo >&2 no gc for you &&
108-
exit 1
109-
EOF
110110
111111
git config gc.auto 3 &&
112112
git config gc.autoDetach false &&
@@ -128,14 +128,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
128128
See "git help gc" for manual housekeeping.
129129
EOF
130130
131-
(
132-
cd pre-auto-gc-hook &&
133-
write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
134-
echo >&2 will gc for you &&
135-
exit 0
136-
EOF
137-
git gc --auto >../out.actual 2>../err.actual
138-
) &&
131+
test_hook -C pre-auto-gc-hook --clobber pre-auto-gc <<-\EOF &&
132+
echo >&2 will gc for you &&
133+
exit 0
134+
EOF
135+
136+
git -C pre-auto-gc-hook gc --auto >out.actual 2>err.actual &&
139137
140138
test_must_be_empty out.actual &&
141139
test_cmp err.expect err.actual

t/t9800-git-p4-basic.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,21 @@ test_expect_success 'run hook p4-pre-submit before submit' '
277277
git commit -m "add hello.txt" &&
278278
git config git-p4.skipSubmitEdit true &&
279279
git p4 submit --dry-run >out &&
280-
grep "Would apply" out &&
281-
mkdir -p .git/hooks &&
282-
write_script .git/hooks/p4-pre-submit <<-\EOF &&
283-
exit 0
284-
EOF
280+
grep "Would apply" out
281+
) &&
282+
test_hook -C "$git" p4-pre-submit <<-\EOF &&
283+
exit 0
284+
EOF
285+
(
286+
cd "$git" &&
285287
git p4 submit --dry-run >out &&
286-
grep "Would apply" out &&
287-
write_script .git/hooks/p4-pre-submit <<-\EOF &&
288-
exit 1
289-
EOF
288+
grep "Would apply" out
289+
) &&
290+
test_hook -C "$git" --clobber p4-pre-submit <<-\EOF &&
291+
exit 1
292+
EOF
293+
(
294+
cd "$git" &&
290295
test_must_fail git p4 submit --dry-run >errs 2>&1 &&
291296
! grep "Would apply" errs
292297
)

0 commit comments

Comments
 (0)