Merge branch 'ij/subtree-reject-v2-config' into jch

The shell script implementation of 'git subtree' has been updated to
check for the presence of the configuration file of the new Rust
implementation, preventing users from accidentally running the old
script on repositories already managed by the new tool.

* ij/subtree-reject-v2-config:
  git-subtree: Bail out if we find output from Rust rewrite (test)
  git-subtree: Bail out if we find output from Rust rewrite
jch
Junio C Hamano 2026-07-24 16:11:57 -07:00
commit 0417aabc00
2 changed files with 36 additions and 0 deletions

View File

@ -278,6 +278,20 @@ main () {
"cmd_$arg_command" "$@"
}

# Usage: reject_if_v2_config REV
#
# Bails if we find .git-subtree/config. This file is used by the RIIR
# git-subtree, which can read data from this script, but which generates
# data that this script cannot cope with. So if we find that the user's
# project has already been processed with the new tool, we stop, to
# avoid generating broken output.
reject_if_v2_config () {
local config=.git-subtree/config
if git rev-parse --verify -q "$rev:$config"; then
die "fatal: tree contains $config: has been processed with new standalone (Rust) git-subtree; use that tool instead of this one. See https://codeberg.org/diziet/git-subtree https://crates.io/crates/git-subtree"
fi
}

# Usage: cache_setup
cache_setup () {
assert test $# = 0
@ -846,6 +860,7 @@ process_split_commit () {
# Or: cmd_add REPOSITORY REF
cmd_add () {

reject_if_v2_config HEAD
ensure_clean

if test $# -eq 1
@ -934,6 +949,8 @@ cmd_split () {
die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
fi

reject_if_v2_config "$rev"

# Now validate prefix against the commit, not the working tree
if ! git cat-file -e "$rev:$dir" 2>/dev/null
then
@ -1034,6 +1051,7 @@ cmd_merge () {
then
repository="$2"
fi
reject_if_v2_config HEAD
ensure_clean

if test -n "$arg_addmerge_squash"

View File

@ -439,6 +439,24 @@ test_expect_success 'split sub dir/ with --rejoin' '
)
'

test_expect_success 'split fail on RIIR git subtree data' '
subtree_test_create_repo "$test_count" &&
subtree_test_create_repo "$test_count/sub proj" &&
test_create_commit "$test_count" main1 &&
test_create_commit "$test_count/sub proj" sub1 &&
(
cd "$test_count" &&
git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
# simulate RIIR git-subtree generated data
mkdir .git-subtree &&
echo "# sabotage" >.git-subtree/config &&
git add .git-subtree/config &&
git commit -m sabotage &&
test_must_fail git subtree split -P "sub dir" HEAD
)
'

# Tests that commits from other subtrees are not processed as
# part of a split.
#