#!/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: subgit check ===" # Step 1: Create an upstream repository mkdir -p upstream/repo1 cd upstream/repo1 git init git config user.email "test@test.com" git config user.name "Test User" echo "test content" > file1.txt git add file1.txt git commit -m "Initial commit" cd "$TESTDIR" # Step 2: Create parent repo and add upstream as subrepo mkdir parent cd parent git init subgit add "$TESTDIR/upstream/repo1" subrepo1 # Step 3: Test that clean repo produces no check warnings echo "=== Test: clean repo should have no output ===" OUTPUT=$(subgit check subrepo1) if [ ! -z "$OUTPUT" ]; then echo "FAIL: clean repo should have no check output, got: $OUTPUT" exit 1 fi # Step 4: Test detection of uncommitted changes (dirty tree) echo "=== Test: dirty tree detection ===" echo "modified" > subrepo1/file1.txt OUTPUT=$(subgit check subrepo1) if ! echo "$OUTPUT" | grep -q "dirty tree"; then echo "FAIL: dirty tree not detected" exit 1 fi # Restore file to clean state git -C subrepo1 checkout file1.txt # Step 5: Test detection of new commits in bare repo echo "=== Test: new commit detection ===" # Add a new commit to upstream cd "$TESTDIR/upstream/repo1" echo "new content" > file2.txt git add file2.txt git commit -m "Second commit" # Fetch and update bare repo to have the new commit cd "$TESTDIR/parent" git -C .subgit/subrepo1 fetch git -C .subgit/subrepo1 update-ref refs/heads/master refs/remotes/origin/master # Check should report that bare repo has a newer commit than .subgitrc OUTPUT=$(subgit check subrepo1) if ! echo "$OUTPUT" | grep -q "new commit"; then echo "FAIL: new commit not detected" exit 1 fi echo "PASS: check test"