#!/bin/sh # SPDX-License-Identifier: MIT set -eu export TZ=UTC LC_ALL=C export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null export GIT_AUTHOR_NAME='Example Author' export GIT_AUTHOR_EMAIL='author@example.invalid' export GIT_COMMITTER_NAME='Example Author' export GIT_COMMITTER_EMAIL='author@example.invalid' export GIT_AUTHOR_DATE='2026-10-25T12:00:00+00:00' export GIT_COMMITTER_DATE='2026-10-25T12:00:00+00:00' test "$(git version)" = 'git version 2.56.0' mkdir merge-example cd merge-example git init -q --template= --initial-branch=main --object-format=sha1 git config commit.gpgsign false git config core.autocrlf false printf 'base\n' > note.txt printf 'original unrelated file\n' > later.txt git add note.txt later.txt git commit -qm 'Base note' git switch -qc topic printf 'topic version\n' > note.txt git commit -qam 'Topic change' git switch -q main printf 'main version\n' > note.txt git commit -qam 'Main change' test -z "$(git status --porcelain=v1)" head_before=$(git rev-parse HEAD) file_before=$(git hash-object note.txt) if git merge --no-edit topic; then printf 'Expected a conflict\n' >&2 exit 1 fi test -n "$(git ls-files --unmerged)" printf 'Conflict: merge is paused with unresolved entries\n' git status --short git merge --abort test "$(git rev-parse HEAD)" = "$head_before" test "$(git hash-object note.txt)" = "$file_before" test -z "$(git status --porcelain=v1)" if git rev-parse --verify -q MERGE_HEAD; then printf 'Merge still in progress\n' >&2 exit 1 fi printf 'Abort: original commit and file restored; no merge in progress\n' git log -1 --format='%h %s' if git merge --no-edit topic; then exit 1 fi printf 'chosen resolution\n' > note.txt printf 'unrelated local work\n' > later.txt git add --resolved -- note.txt later.txt test -z "$(git ls-files --unmerged)" test "$(git show :note.txt)" = 'chosen resolution' test "$(git status --porcelain=v1 -- later.txt)" = ' M later.txt' test -z "$(git diff --cached -- later.txt)" git diff --cached -- note.txt printf 'Resolved staging: resolution staged; unrelated tracked edit unstaged\n' git merge --abort test "$(git rev-parse HEAD)" = "$head_before" test "$(git hash-object note.txt)" = "$file_before" test "$(cat later.txt)" = 'unrelated local work' printf 'Second abort: tracked file restored; unrelated tracked edit remains\n'