git-subtree: Bail out if we find output from Rust rewrite

This is going to be forward compatible, but not backward compatible: projects are expected to adopt the new tool, but not go back to this old one. CC: Colin Stagner <ask+git@howdoi.land> CC: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ian Jackson committed Jul 6, 2026 at 12:58 UTC cd6ad979ab5a81800c40e32e7e92bdc6f0ec0090
1 file changed +18
contrib/subtree/git-subtree.sh
+18
@@ -278,6 +278,20 @@ main () {
278 "cmd_$arg_command" "$@"
279 }
280
281 +# Usage: reject_if_v2_config REV
282 +#
283 +# Bails if we find .git-subtree/config. This file is used by the RIIR
284 +# git-subtree, which can read data from this script, but which generates
285 +# data that this script cannot cope with. So if we find that the user's
286 +# project has already been processed with the new tool, we stop, to
287 +# avoid generating broken output.
288 +reject_if_v2_config () {
289 + local config=.git-subtree/config
290 + if git rev-parse --verify -q "$rev:$config"; then
291 + 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"
292 + fi
293 +}
294 +
295 # Usage: cache_setup
296 cache_setup () {
297 assert test $# = 0
@@ -846,6 +860,7 @@ process_split_commit () {
860 # Or: cmd_add REPOSITORY REF
861 cmd_add () {
862
863 + reject_if_v2_config HEAD
864 ensure_clean
865
866 if test $# -eq 1
@@ -934,6 +949,8 @@ cmd_split () {
949 die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
950 fi
951
952 + reject_if_v2_config "$rev"
953 +
954 # Now validate prefix against the commit, not the working tree
955 if ! git cat-file -e "$rev:$dir" 2>/dev/null
956 then
@@ -1034,6 +1051,7 @@ cmd_merge () {
1051 then
1052 repository="$2"
1053 fi
1054 + reject_if_v2_config HEAD
1055 ensure_clean
1056
1057 if test -n "$arg_addmerge_squash"