Add --annotate option, and create recognizable file content during tests.
Avery Pennarun committed
Apr 26, 2009 at 08:59 UTC
d0eb1b1417b855b262b5ad31d025840ea6e52094
2 files changed
+42
-31
git-subtree.sh
+5
-1
@@ -17,6 +17,7 @@ h,help show the help
17
q quiet
18
prefix= the name of the subdir to split out
19
options for 'split'
20
+annotate= add a prefix to commit message of new commits
21
onto= try connecting new tree to an existing one
22
rejoin merge the new branch back into HEAD
23
ignore-joins ignore prior --rejoin commits
@@ -30,6 +31,7 @@ command=
31
onto=
32
rejoin=
33
ignore_joins=
34
+annotate=
35
36
debug()
37
{
@@ -55,6 +57,8 @@ while [ $# -gt 0 ]; do
57
shift
58
case "$opt" in
59
-q) quiet=1 ;;
60
+ --annotate) annotate="$1"; shift ;;
61
+ --no-annotate) annotate= ;;
62
--prefix) prefix="$1"; shift ;;
63
--no-prefix) prefix= ;;
64
--onto) onto="$1"; shift ;;
@@ -178,7 +182,7 @@ copy_commit()
182
GIT_COMMITTER_NAME \
183
GIT_COMMITTER_EMAIL \
184
GIT_COMMITTER_DATE
181
- (echo -n '*'; cat ) | # FIXME
185
+ (echo -n "$annotate"; cat ) |
186
git commit-tree "$2" $3 # reads the rest of stdin
187
) || die "Can't copy commit $1"
188
}
test.sh
+37
-30
@@ -1,4 +1,11 @@
1
#!/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
+
9
. shellopts.sh
10
set -e
11
@@ -8,27 +15,27 @@ mkdir mainline subproj
15
cd subproj
16
git init
17
11
-touch sub1
18
+create sub1
19
git add sub1
13
-git commit -m 'sub-1'
20
+git commit -m 'sub1'
21
git branch sub1
22
git branch -m master subproj
23
17
-touch sub2
24
+create sub2
25
git add sub2
19
-git commit -m 'sub-2'
26
+git commit -m 'sub2'
27
git branch sub2
28
22
-touch sub3
29
+create sub3
30
git add sub3
24
-git commit -m 'sub-3'
31
+git commit -m 'sub3'
32
git branch sub3
33
34
cd ../mainline
35
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'
39
git branch -m master mainline
40
41
git fetch ../subproj sub1
@@ -38,49 +45,49 @@ git subtree add --prefix=subdir FETCH_HEAD
45
# this shouldn't actually do anything, since FETCH_HEAD is already a parent
46
git merge -m 'merge -s -ours' -s ours FETCH_HEAD
47
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'
51
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'
55
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'
59
60
git fetch ../subproj sub2
61
git branch sub2 FETCH_HEAD
62
git subtree merge --prefix=subdir FETCH_HEAD
63
git branch pre-split
64
58
-split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin)
65
+split1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin)
66
echo "split1={$split1}"
67
git branch split1 "$split1"
68
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'
72
73
cd ../subproj
74
git fetch ../mainline split1
75
git branch split1 FETCH_HEAD
76
git merge FETCH_HEAD
77
71
-touch sub6
72
-git add sub6
73
-git commit -m 'sub6'
78
+create sub9
79
+git add sub9
80
+git commit -m 'sub9'
81
82
cd ../mainline
76
-split2=$(git subtree split --prefix subdir --rejoin)
83
+split2=$(git subtree split --annotate='*' --prefix subdir --rejoin)
84
git branch split2 "$split2"
85
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'
89
83
-split3=$(git subtree split --prefix subdir --rejoin)
90
+split3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
91
git branch split3 "$split3"
92
93
cd ../subproj