Skip to content

Commit d0eb1b1

Browse files
committed
Add --annotate option, and create recognizable file content during tests.
1 parent 8c38475 commit d0eb1b1

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

git-subtree.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ h,help show the help
1717
q quiet
1818
prefix= the name of the subdir to split out
1919
options for 'split'
20+
annotate= add a prefix to commit message of new commits
2021
onto= try connecting new tree to an existing one
2122
rejoin merge the new branch back into HEAD
2223
ignore-joins ignore prior --rejoin commits
@@ -30,6 +31,7 @@ command=
3031
onto=
3132
rejoin=
3233
ignore_joins=
34+
annotate=
3335

3436
debug()
3537
{
@@ -55,6 +57,8 @@ while [ $# -gt 0 ]; do
5557
shift
5658
case "$opt" in
5759
-q) quiet=1 ;;
60+
--annotate) annotate="$1"; shift ;;
61+
--no-annotate) annotate= ;;
5862
--prefix) prefix="$1"; shift ;;
5963
--no-prefix) prefix= ;;
6064
--onto) onto="$1"; shift ;;
@@ -178,7 +182,7 @@ copy_commit()
178182
GIT_COMMITTER_NAME \
179183
GIT_COMMITTER_EMAIL \
180184
GIT_COMMITTER_DATE
181-
(echo -n '*'; cat ) | # FIXME
185+
(echo -n "$annotate"; cat ) |
182186
git commit-tree "$2" $3 # reads the rest of stdin
183187
) || die "Can't copy commit $1"
184188
}

test.sh

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/bin/bash -x
2+
create()
3+
{
4+
for d in 1 2 3 4 5 6 7 8 9 10; do
5+
echo "$1"
6+
done >"$1"
7+
}
8+
29
. shellopts.sh
310
set -e
411

@@ -8,27 +15,27 @@ mkdir mainline subproj
815
cd subproj
916
git init
1017

11-
touch sub1
18+
create sub1
1219
git add sub1
13-
git commit -m 'sub-1'
20+
git commit -m 'sub1'
1421
git branch sub1
1522
git branch -m master subproj
1623

17-
touch sub2
24+
create sub2
1825
git add sub2
19-
git commit -m 'sub-2'
26+
git commit -m 'sub2'
2027
git branch sub2
2128

22-
touch sub3
29+
create sub3
2330
git add sub3
24-
git commit -m 'sub-3'
31+
git commit -m 'sub3'
2532
git branch sub3
2633

2734
cd ../mainline
2835
git init
29-
touch main1
30-
git add main1
31-
git commit -m 'main-1'
36+
create main4
37+
git add main4
38+
git commit -m 'main4'
3239
git branch -m master mainline
3340

3441
git fetch ../subproj sub1
@@ -38,49 +45,49 @@ git subtree add --prefix=subdir FETCH_HEAD
3845
# this shouldn't actually do anything, since FETCH_HEAD is already a parent
3946
git merge -m 'merge -s -ours' -s ours FETCH_HEAD
4047

41-
touch subdir/main-sub3
42-
git add subdir/main-sub3
43-
git commit -m 'main-sub3'
48+
create subdir/main-sub5
49+
git add subdir/main-sub5
50+
git commit -m 'main-sub5'
4451

45-
touch main-2
46-
git add main-2
47-
git commit -m 'main-2 boring'
52+
create main6
53+
git add main6
54+
git commit -m 'main6 boring'
4855

49-
touch subdir/main-sub4
50-
git add subdir/main-sub4
51-
git commit -m 'main-sub4'
56+
create subdir/main-sub7
57+
git add subdir/main-sub7
58+
git commit -m 'main-sub7'
5259

5360
git fetch ../subproj sub2
5461
git branch sub2 FETCH_HEAD
5562
git subtree merge --prefix=subdir FETCH_HEAD
5663
git branch pre-split
5764

58-
split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin)
65+
split1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin)
5966
echo "split1={$split1}"
6067
git branch split1 "$split1"
6168

62-
touch subdir/main-sub5
63-
git add subdir/main-sub5
64-
git commit -m 'main-sub5'
69+
create subdir/main-sub8
70+
git add subdir/main-sub8
71+
git commit -m 'main-sub8'
6572

6673
cd ../subproj
6774
git fetch ../mainline split1
6875
git branch split1 FETCH_HEAD
6976
git merge FETCH_HEAD
7077

71-
touch sub6
72-
git add sub6
73-
git commit -m 'sub6'
78+
create sub9
79+
git add sub9
80+
git commit -m 'sub9'
7481

7582
cd ../mainline
76-
split2=$(git subtree split --prefix subdir --rejoin)
83+
split2=$(git subtree split --annotate='*' --prefix subdir --rejoin)
7784
git branch split2 "$split2"
7885

79-
touch subdir/main-sub7
80-
git add subdir/main-sub7
81-
git commit -m 'main-sub7'
86+
create subdir/main-sub10
87+
git add subdir/main-sub10
88+
git commit -m 'main-sub10'
8289

83-
split3=$(git subtree split --prefix subdir --rejoin)
90+
split3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
8491
git branch split3 "$split3"
8592

8693
cd ../subproj

0 commit comments

Comments
 (0)