#!/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 with branches ===" # Step 1: Create an upstream repository with multiple branches mkdir -p upstream/repo1 cd upstream/repo1 git init git config user.email "test@test.com" git config user.name "Test User" # Create master branch with file1.txt echo "test content" > file1.txt git add file1.txt git commit -m "Initial commit on master" # Create develop branch with file2.txt git checkout -b develop echo "develop content" > file2.txt git add file2.txt git commit -m "Commit on develop" DEVELOP_COMMIT=$(git rev-parse HEAD) # Switch back to master so upstream is on a different branch git checkout master cd "$TESTDIR" # Step 2: Create parent repo and track the develop branch specifically mkdir parent cd parent git init echo "=== Test: add with specific branch ===" subgit add -b develop ../upstream/repo1 subrepo1 # Step 3: Verify that the develop branch was tracked # Check that branch is recorded in .subgitrc source .subgitrc if [ "${subgitinfo[subrepo1/branch]}" != "develop" ]; then echo "FAIL: branch not set to develop (got ${subgitinfo[subrepo1/branch]})" exit 1 fi # Check that the bare repo is on the develop branch CURRENT_BRANCH=$(git -C .subgit/subrepo1 branch --show-current) if [ "$CURRENT_BRANCH" != "develop" ]; then echo "FAIL: bare repo not on develop branch (got $CURRENT_BRANCH)" exit 1 fi # Check that develop-specific file is present if [ ! -f subrepo1/file2.txt ]; then echo "FAIL: file2.txt from develop branch not present" exit 1 fi # Optional check: verify we're not accidentally on master if [ -f subrepo1/file1.txt ]; then if ! git -C subrepo1 ls-tree HEAD | grep -q file1.txt; then echo "Note: file1.txt exists but not in develop tree (expected)" fi fi echo "PASS: branches test"