Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b0ab2b7

Browse files
chriscoolgitster
authored andcommitted
contrib: add convert-grafts-to-replace-refs.sh
This patch adds into contrib/ an example script to convert grafts from an existing grafts file into replace refs using the new --graft option of "git replace". While at it let's mention this new script in the "git replace" documentation for the --graft option. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78024c4 commit b0ab2b7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Documentation/git-replace.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ OPTIONS
7979
content as <commit> except that its parents will be
8080
[<parent>...] instead of <commit>'s parents. A replacement ref
8181
is then created to replace <commit> with the newly created
82-
commit.
82+
commit. See contrib/convert-grafts-to-replace-refs.sh for an
83+
example script based on this option that can convert grafts to
84+
replace refs.
8385

8486
-l <pattern>::
8587
--list <pattern>::
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
# You should execute this script in the repository where you
4+
# want to convert grafts to replace refs.
5+
6+
GRAFTS_FILE="${GIT_DIR:-.git}/info/grafts"
7+
8+
. $(git --exec-path)/git-sh-setup
9+
10+
test -f "$GRAFTS_FILE" || die "Could not find graft file: '$GRAFTS_FILE'"
11+
12+
grep '^[^# ]' "$GRAFTS_FILE" |
13+
while read definition
14+
do
15+
if test -n "$definition"
16+
then
17+
echo "Converting: $definition"
18+
git replace --graft $definition ||
19+
die "Conversion failed for: $definition"
20+
fi
21+
done
22+
23+
mv "$GRAFTS_FILE" "$GRAFTS_FILE.bak" ||
24+
die "Could not rename '$GRAFTS_FILE' to '$GRAFTS_FILE.bak'"
25+
26+
echo "Success!"
27+
echo "All the grafts in '$GRAFTS_FILE' have been converted to replace refs!"
28+
echo "The grafts file '$GRAFTS_FILE' has been renamed: '$GRAFTS_FILE.bak'"

0 commit comments

Comments
 (0)