Skip to content

Commit 4ed8b58

Browse files
committed
git-son: add tests
Add t5151-son.sh with nine test cases covering: - basic child repository creation - parent remote configuration in the child - .gitignore update in the parent - initial commit presence in the child - failure when the target directory already exists - --branch without --inherit is rejected cleanly - no leftover directory on validation failure - --inherit fetches parent history Register the test in t/meson.build so the meson build system discovers and runs it. Assisted-by: Claude Opus 4.6 Signed-off-by: Evan Haque <evanhaque1@gmail.com>
1 parent 6523818 commit 4ed8b58

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ integration_tests = [
591591
't5004-archive-corner-cases.sh',
592592
't5100-mailinfo.sh',
593593
't5150-request-pull.sh',
594+
't5151-son.sh',
594595
't5200-update-server-info.sh',
595596
't5300-pack-object.sh',
596597
't5301-sliding-window.sh',

t/t5151-son.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
test_description='Test git son command.'
4+
5+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7+
8+
. ./test-lib.sh
9+
10+
test_expect_success 'setup parent repository' '
11+
echo "parent content" >file.txt &&
12+
git add file.txt &&
13+
git commit -m "Initial parent commit"
14+
'
15+
16+
test_expect_success 'son creates child repository' '
17+
git son my-child &&
18+
test -d my-child &&
19+
test -d my-child/.git
20+
'
21+
22+
test_expect_success 'son sets parent remote in child' '
23+
(
24+
cd my-child &&
25+
git remote get-url parent
26+
)
27+
'
28+
29+
test_expect_success 'son adds child to parent .gitignore' '
30+
grep "my-child/" .gitignore
31+
'
32+
33+
test_expect_success 'son child has initial commit' '
34+
(
35+
cd my-child &&
36+
test $(git log --oneline | wc -l) -eq 1
37+
)
38+
'
39+
40+
test_expect_success 'son fails if target already exists' '
41+
test_must_fail git son my-child
42+
'
43+
44+
test_expect_success 'son with --branch requires --inherit' '
45+
test_must_fail git son --branch main branch-child
46+
'
47+
48+
test_expect_success 'son with --branch leaves no directory on failure' '
49+
! test -e branch-child
50+
'
51+
52+
test_expect_success 'son with --inherit fetches parent history' '
53+
git init --bare "$TRASH_DIRECTORY/parent.git" &&
54+
git push "$TRASH_DIRECTORY/parent.git" main &&
55+
git remote add origin "file://$TRASH_DIRECTORY/parent.git" &&
56+
git son --inherit inherited-child &&
57+
(
58+
cd inherited-child &&
59+
git log --oneline parent/main
60+
)
61+
'
62+
63+
test_done

0 commit comments

Comments
 (0)