patchbomb: added --git option
[guilt.git] / guilt-import-commit
blob30d09625a839a2352182d18d544dbd02335c65d8
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 USAGE="[<hash> | <since>..[<until>] | ..<until>]"
7 . `dirname $0`/guilt
9 if [ $# -ne 1 ] || [ -z "$1" ]; then
10 die "You must specify a range of commits"
13 rhash=`munge_hash_range $1`
15 # make sure that there are no unapplied changes
16 if ! must_commit_first; then
17 die "Uncommited changes detected. Refresh first."
20 disp "About to begin conversion..." >&2
21 disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2
23 for rev in `git rev-list $rhash`; do
24 s=`git log --pretty=oneline -1 $rev | cut -c 42-`
26 fname=`echo $s | sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \
27 -e "s/['\\[{}]//g" -e 's/]//g' -e 's/\*/-/g' \
28 -e 's/\?/-/g' | tr A-Z a-z`
30 disp "Converting `echo $rev | cut -c 1-8` as $fname"
32 mangle_prefix=1
33 fname_base=$fname
34 while [ -f "$GUILT_DIR/$branch/$fname" ]; do
35 fname="$fname_base-$mangle_prefix"
36 mangle_prefix=`expr $mangle_prefix + 1`
37 disp "Patch under that name exists...trying '$fname'"
38 done
41 do_make_header $rev
42 echo ""
43 git diff $rev^..$rev
44 ) > $GUILT_DIR/$branch/$fname
46 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
47 # timestamp on the patch
49 # insert the patch name into the series file
50 series_insert_patch $fname
52 # Only reset if the commit was on this branch
53 if head_check $rev 2> /dev/null; then
54 # BEWARE: "git reset" ahead! Is there a way to verify that
55 # we really created a patch? - We don't want to lose any
56 # history.
57 git reset --hard $rev^ > /dev/null
58 elif [ -z "$warned" ]; then
59 disp "Warning: commit $rev is not the HEAD...preserving commit" >&2
60 disp "Warning: (this message is displayed only once)" >&2
61 warned=t
63 done
65 disp "Done." >&2
66 disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2