Skip to content

Commit 0124ea9

Browse files
committed
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
2 parents 36e9f0c + 20b117c commit 0124ea9

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

contrib/subtree/git-subtree.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ main () {
278278
"cmd_$arg_command" "$@"
279279
}
280280

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+
281295
# Usage: cache_setup
282296
cache_setup () {
283297
assert test $# = 0
@@ -846,6 +860,7 @@ process_split_commit () {
846860
# Or: cmd_add REPOSITORY REF
847861
cmd_add () {
848862

863+
reject_if_v2_config HEAD
849864
ensure_clean
850865

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

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

10391057
if test -n "$arg_addmerge_squash"

contrib/subtree/t/t7900-subtree.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,24 @@ test_expect_success 'split sub dir/ with --rejoin' '
439439
)
440440
'
441441

442+
test_expect_success 'split fail on RIIR git subtree data' '
443+
subtree_test_create_repo "$test_count" &&
444+
subtree_test_create_repo "$test_count/sub proj" &&
445+
test_create_commit "$test_count" main1 &&
446+
test_create_commit "$test_count/sub proj" sub1 &&
447+
(
448+
cd "$test_count" &&
449+
git fetch ./"sub proj" HEAD &&
450+
git subtree add --prefix="sub dir" FETCH_HEAD &&
451+
# simulate RIIR git-subtree generated data
452+
mkdir .git-subtree &&
453+
echo "# sabotage" >.git-subtree/config &&
454+
git add .git-subtree/config &&
455+
git commit -m sabotage &&
456+
test_must_fail git subtree split -P "sub dir" HEAD
457+
)
458+
'
459+
442460
# Tests that commits from other subtrees are not processed as
443461
# part of a split.
444462
#

0 commit comments

Comments
 (0)