Skip to content
This repository was archived by the owner on Nov 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/core_resolve_target.bats
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ teardown() {
local foreign="$TEST_WORKTREES_DIR/impostor"
mkdir -p "$foreign"
git -C "$foreign" init --quiet
git -C "$foreign" -c user.name=Test -c user.email=test@example.com commit --allow-empty -m init --quiet
git -C "$foreign" -c user.name=Test -c user.email=test@example.com -c commit.gpgsign=false \
commit --allow-empty -m init --quiet
git -C "$foreign" branch -m foreign-branch

run resolve_target "impostor" "$TEST_REPO" "$TEST_WORKTREES_DIR" ""
Expand Down
76 changes: 76 additions & 0 deletions tests/fixture_signing.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bats
# Fixture commits must not depend on a developer's signing key or agent.

load test_helper

# Isolate the test process's home and signer, including Git before 2.32.
setup() {
local fixture_home="$BATS_TEST_TMPDIR/home"
mkdir -p "$fixture_home"
export GIT_CONFIG_NOSYSTEM=1
export HOME="$fixture_home"
export XDG_CONFIG_HOME="$BATS_TEST_TMPDIR/xdg-config"
export GIT_CONFIG_GLOBAL="$fixture_home/.gitconfig"
export FIXTURE_SIGNER_LOG="$BATS_TEST_TMPDIR/signer.log"
local signer="$BATS_TEST_TMPDIR/failing-signer"
cat > "$signer" <<'SCRIPT'
#!/usr/bin/env bash
printf 'invoked\n' >> "$FIXTURE_SIGNER_LOG"
exit 1
SCRIPT
chmod +x "$signer"
git config --file "$GIT_CONFIG_GLOBAL" commit.gpgsign true
git config --file "$GIT_CONFIG_GLOBAL" gpg.format openpgp
git config --file "$GIT_CONFIG_GLOBAL" gpg.program "$signer"
git config --file "$GIT_CONFIG_GLOBAL" gpg.openpgp.program "$signer"
git config --file "$GIT_CONFIG_GLOBAL" user.signingkey fixture-only
git config --file "$GIT_CONFIG_GLOBAL" test.inherited preserved
cp "$GIT_CONFIG_GLOBAL" "$BATS_TEST_TMPDIR/global.before"
}

# Remove disposable worktrees and verify that the signing config was preserved.
teardown() {
if [ -n "${TEST_REPO:-}" ]; then
teardown_integration_repo
fi
cmp "$BATS_TEST_TMPDIR/global.before" "$GIT_CONFIG_GLOBAL"
}

@test "signing control invokes only the harmless failing signer" {
local repo="$BATS_TEST_TMPDIR/control"
git init --quiet "$repo"

run git -C "$repo" -c user.name=Test -c user.email=test@example.com \
commit --allow-empty --quiet -m control

[ "$status" -ne 0 ]
[ "$(cat "$FIXTURE_SIGNER_LOG")" = invoked ]
run git -C "$repo" rev-parse --verify HEAD
[ "$status" -ne 0 ]
}

@test "integration fixture creates initial and subsequent commits without signing" {
setup_integration_repo
[ "$(git log -1 --format=%s)" = init ]

git commit --allow-empty --quiet -m subsequent

[ "$(git rev-list --count HEAD)" -eq 2 ]
[ "$(git log -1 --format=%s)" = subsequent ]
[ "$(git config --global --get commit.gpgsign)" = true ]
[ "$(git config --get test.inherited)" = preserved ]
[ ! -e "$FIXTURE_SIGNER_LOG" ]
}

@test "linked fixture worktrees inherit unsigned commits" {
setup_integration_repo
source_gtr_libs
create_test_worktree fixture-branch

git -C "$TEST_WT_PATH" commit --allow-empty --quiet -m linked

[ "$(git -C "$TEST_WT_PATH" rev-list --count HEAD)" -eq 2 ]
[ "$(git -C "$TEST_WT_PATH" log -1 --format=%s)" = linked ]
[ "$(git rev-list --count HEAD)" -eq 1 ]
[ ! -e "$FIXTURE_SIGNER_LOG" ]
}
9 changes: 6 additions & 3 deletions tests/init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ run_generated_bash_cd_completion() (
[ ! -e completion-backtick-marker ]
)

# Run generated Bash/Zsh postCd hooks and report their execution order.
run_generated_post_cd_hooks() {
local shell_name="$1"

Expand All @@ -125,7 +126,7 @@ trap cleanup EXIT
git -C "$repo" init --quiet
git -C "$repo" config user.name "Test User"
git -C "$repo" config user.email "test@example.com"
git -C "$repo" commit --allow-empty -m "init" --quiet
git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet

git -C "$repo" config --add gtr.hook.postCd 'echo first >> "$REPO_ROOT/order"'
git -C "$repo" config --add gtr.hook.postCd 'cat'
Expand All @@ -140,6 +141,7 @@ printf '\n'
SCRIPT
}

# Exercise generated Fish hooks against a trusted or untrusted shared config.
run_generated_fish_gtrconfig_post_cd_hooks() {
local trust_state="$1"
local root repo wt xdg init_file
Expand All @@ -153,7 +155,7 @@ run_generated_fish_gtrconfig_post_cd_hooks() {
git init --quiet "$repo"
git -C "$repo" config user.name "Test User"
git -C "$repo" config user.email "test@example.com"
git -C "$repo" commit --allow-empty -m "init" --quiet
git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet
git -C "$repo" worktree add --quiet "$wt" -b feature

cat > "$repo/.gtrconfig" <<'CFG'
Expand Down Expand Up @@ -283,6 +285,7 @@ mark_pr207_commands_trusted() {
printf '%s/.gtrconfig\n' "$repo_root" > "$XDG_CONFIG_HOME/gtr/trusted/$key"
}

# Verify that generated shell helpers reject v2 trust and honor fresh approval.
run_generated_v2_trust_upgrade() (
set -e
local shell_name="$1" fixture
Expand All @@ -292,7 +295,7 @@ run_generated_v2_trust_upgrade() (
export XDG_CONFIG_HOME="$fixture/config" XDG_DATA_HOME="$fixture/data"
git init --quiet "$REPO_FIXTURE"
git -C "$REPO_FIXTURE" -c user.name=Fixture -c user.email=fixture@example.test \
commit --allow-empty --quiet -m init
-c commit.gpgsign=false commit --allow-empty --quiet -m init
git config -f "$REPO_FIXTURE/.gtrconfig" hooks.postCd 'sh "$REPO_ROOT/bootstrap.sh"'
printf 'echo original > "$REPO_ROOT/hook-result"\n' > "$REPO_FIXTURE/bootstrap.sh"
mark_pr207_commands_trusted "$REPO_FIXTURE/.gtrconfig"
Expand Down
2 changes: 1 addition & 1 deletion tests/provider.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ assert_gitlab_state() {
git -C "$test_repo" init --quiet
git -C "$test_repo" config user.name "Test User"
git -C "$test_repo" config user.email "test@example.com"
git -C "$test_repo" commit --allow-empty -m init --quiet
git -C "$test_repo" -c commit.gpgsign=false commit --allow-empty -m init --quiet
git -C "$test_repo" remote add upstream https://example.com/repo.git
git -C "$test_repo" update-ref refs/remotes/upstream/main HEAD

Expand Down
2 changes: 1 addition & 1 deletion tests/resolve_base_dir.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setup() {
git -C "$TEST_REPO" init --quiet
git -C "$TEST_REPO" config user.name "Test User"
git -C "$TEST_REPO" config user.email "test@example.com"
git -C "$TEST_REPO" commit --allow-empty -m "init" --quiet
git -C "$TEST_REPO" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet
}

teardown() {
Expand Down
1 change: 1 addition & 0 deletions tests/sparse.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ setup() {
git -C "$TEST_REPO" init --quiet
git -C "$TEST_REPO" config user.name "Test User"
git -C "$TEST_REPO" config user.email "test@example.com"
git -C "$TEST_REPO" config --local commit.gpgsign false
mkdir -p "$TEST_REPO/apps/web" "$TEST_REPO/apps/api" "$TEST_REPO/packages" "$TEST_REPO/docs"
# Git 2.25 sparse init needs a root file to avoid an empty initial checkout.
echo root > "$TEST_REPO/README.md"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ setup_integration_repo() {
git -C "$TEST_REPO" init --quiet
git -C "$TEST_REPO" config user.name "Test User"
git -C "$TEST_REPO" config user.email "test@example.com"
# Cover later fixture commits and linked worktrees as well as the initial commit.
git -C "$TEST_REPO" config --local commit.gpgsign false
git -C "$TEST_REPO" commit --allow-empty -m "init" --quiet
export GTR_DIR="$PROJECT_ROOT"
cd "$TEST_REPO" || return 1
Expand Down
Loading