repair: new command to repair repository state
[guilt.git] / guilt-import-commit
blob28846e1eadb73f6037d8217d3e89abb6c6c2e2fa
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 echo "About to begin conversion..." >&2
21 echo "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' | tr A-Z a-z`
29 echo "Converting `echo $rev | cut -c 1-8` as $fname"
31 mangle_prefix=1
32 fname_base=$fname
33 while [ -f "$GUILT_DIR/$branch/$fname" ]; do
34 fname="$fname_base-$mangle_prefix"
35 mangle_prefix=`expr $mangle_prefix + 1`
36 echo "Patch under that name exists...trying '$fname'"
37 done
40 do_make_header $rev
41 echo ""
42 git-diff $rev^..$rev
43 ) > $GUILT_DIR/$branch/$fname
45 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
46 # timestamp on the patch
48 # insert the patch name into the series file
49 series_insert_patch $fname
51 # Only reset if the commit was on this branch
52 if head_check $rev 2> /dev/null; then
53 # BEWARE: git-reset ahead! Is there a way to verify that we really
54 # created a patch? - We don't want to lose any history.
55 git-reset --hard $rev^ > /dev/null
56 elif [ -z "$warned" ]; then
57 echo "Warning: commit $rev is not the HEAD...preserving commit" >&2
58 echo "Warning: (this message is displayed only once)" >&2
59 warned=t
61 done
63 echo "Done." >&2
64 echo "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2