#!/bin/bash set -e # Setup: Add src directory to PATH and create isolated test directory SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../src" && pwd)" export PATH="$SRCDIR:$PATH" TESTDIR=$(mktemp -d) trap "rm -rf '$TESTDIR'" EXIT cd "$TESTDIR" echo "=== Test: recursive subgit ===" # Step 1: Create two upstream repositories mkdir -p upstream/repo1 upstream/repo2 cd upstream/repo1 git init echo "test1" > file1.txt git add file1.txt git commit -m "Initial commit repo1" cd ../repo2 git init echo "test2" > file2.txt git add file2.txt git commit -m "Initial commit repo2" cd "$TESTDIR" # Step 2: Create parent repo with a subrepo that itself has a nested subrepo mkdir parent cd parent git init # Add first-level subrepo subgit add "$TESTDIR/upstream/repo1" subrepo1 # Make the subrepo directory into a subgit container with its own subrepo cd subrepo1 git init subgit add "$TESTDIR/upstream/repo2" nested-repo cd "$TESTDIR/parent" # Step 3: Test that init without -r flag does not initialize nested subrepos echo "=== Test: init without -r flag ===" rm -rf subrepo1/nested-repo subgit init -f subrepo1 # nested-repo should not exist (not initialized recursively) if [ -d subrepo1/nested-repo ]; then echo "FAIL: nested repo should not be initialized without -r flag" exit 1 fi # Step 4: Test that init with -r flag initializes nested subrepos echo "=== Test: init with -r flag ===" subgit init -r -f subrepo1 # nested-repo should now exist with its files if [ ! -f subrepo1/nested-repo/file2.txt ]; then echo "FAIL: nested repo not initialized with -r flag" exit 1 fi # Verify .git symlink was created for nested repo if [ ! -L subrepo1/nested-repo/.git ]; then echo "FAIL: nested repo .git symlink not created" exit 1 fi echo "PASS: recursive test"