summaryrefslogtreecommitdiffstats
path: root/tests/test-branches.sh
blob: ffa1667357116ecf4f7f6aa76870e6788163bf83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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"