[PATCH 5/5] git-son: add tests
- From
- Evan Haque via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 26, 2026, 16:47 UTC
- Message-ID
- <4ed8b58566dbe6f56d09c8e98f155cff4a297cfe.1779814052.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2122.git.1779814052.gitgitgadget@gmail.com>
From: Evan Haque <evanhaque1@gmail.com>
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> --- t/meson.build | 1 + t/t5151-son.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 t/t5151-son.sh
diff --git a/t/meson.build b/t/meson.build index fd955f44ef..523062df66 100644 --- a/t/meson.build +++ b/t/meson.build @@ -591,6 +591,7 @@ integration_tests = [ 't5004-archive-corner-cases.sh', 't5100-mailinfo.sh', 't5150-request-pull.sh', + 't5151-son.sh', 't5200-update-server-info.sh', 't5300-pack-object.sh', 't5301-sliding-window.sh', diff --git a/t/t5151-son.sh b/t/t5151-son.sh new file mode 100755 index 0000000000..826cbbfa66 --- /dev/null +++ b/t/t5151-son.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +test_description='Test git son command.' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +test_expect_success 'setup parent repository' ' + echo "parent content" >file.txt && + git add file.txt && + git commit -m "Initial parent commit" +' + +test_expect_success 'son creates child repository' ' + git son my-child && + test -d my-child && + test -d my-child/.git +' + +test_expect_success 'son sets parent remote in child' ' + ( + cd my-child && + git remote get-url parent + ) +' + +test_expect_success 'son adds child to parent .gitignore' ' + grep "my-child/" .gitignore +' + +test_expect_success 'son child has initial commit' ' + ( + cd my-child && + test $(git log --oneline | wc -l) -eq 1 + ) +' + +test_expect_success 'son fails if target already exists' ' + test_must_fail git son my-child +' + +test_expect_success 'son with --branch requires --inherit' ' + test_must_fail git son --branch main branch-child +' + +test_expect_success 'son with --branch leaves no directory on failure' ' + ! test -e branch-child +' + +test_expect_success 'son with --inherit fetches parent history' ' + git init --bare "$TRASH_DIRECTORY/parent.git" && + git push "$TRASH_DIRECTORY/parent.git" main && + git remote add origin "file://$TRASH_DIRECTORY/parent.git" && + git son --inherit inherited-child && + ( + cd inherited-child && + git log --oneline parent/main + ) +' + +test_done
-- gitgitgadget