doc: git doesn't use git-foo invocations.
[guilt.git] / guilt-import-commit
blob1da7c8ea83f72845bbc2617aa70f4af6f94be11c
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
6 USAGE="[<hash> | <since>..[<until>] | ..<until>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ $# -ne 1 ] || [ -z "$1" ]; then
15 die "You must specify a range of commits"
18 rhash=`munge_hash_range $1`
20 # make sure that there are no unapplied changes
21 if ! must_commit_first; then
22 die "Uncommited changes detected. Refresh first."
25 disp "About to begin conversion..." >&2
26 disp "Current head: `git rev-parse \`git_branch\``" >&2
28 for rev in `git rev-list $rhash`; do
29 s=`git log --no-decorate --pretty=oneline -1 $rev | cut -c 42-`
31 # Try to convert the first line of the commit message to a
32 # valid patch name.
33 fname=`printf %s "$s" | sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \
34 -e "s/['\\[{}]//g" -e 's/]//g' -e 's/\*/-/g' \
35 -e 's/\?/-/g' -e 's/\.\.\.*/./g' -e 's/^\.//' \
36 -e 's/\.patch$//' -e 's/\.$//' | tr A-Z a-z`
38 if ! valid_patchname "$fname"; then
39 # Try harder to make it a legal commit name by
40 # removing all but a few safe characters.
41 fname=`echo $fname|tr -d -c _a-zA-Z0-9---/\\n`
43 if ! valid_patchname "$fname"; then
44 # If we failed to derive a legal patch name, use the
45 # name "x". (If this happens, we likely have to
46 # append a suffix to make the name unique.)
47 fname=x
50 disp "Converting `echo $rev | cut -c 1-8` as $fname"
52 mangle_prefix=1
53 fname_base=$fname
54 while [ -f "$GUILT_DIR/$branch/$fname.patch" ]; do
55 fname="$fname_base-$mangle_prefix"
56 mangle_prefix=`expr $mangle_prefix + 1`
57 disp "Patch under that name exists...trying '$fname'"
58 done
59 fname="$fname".patch
62 do_make_header $rev
63 echo ""
64 git diff --binary $rev^..$rev
65 ) > "$GUILT_DIR/$branch/$fname"
67 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
68 # timestamp on the patch
70 # insert the patch name into the series file
71 series_insert_patch $fname
73 # Only reset if the commit was on this branch
74 if head_check $rev 2> /dev/null; then
75 # BEWARE: "git reset" ahead! Is there a way to verify that
76 # we really created a patch? - We don't want to lose any
77 # history.
78 git reset --hard $rev^ > /dev/null
79 elif [ -z "$warned" ]; then
80 disp "Warning: commit $rev is not the HEAD...preserving commit" >&2
81 disp "Warning: (this message is displayed only once)" >&2
82 warned=t
84 done
86 disp "Done." >&2
87 disp "Current head: `git rev-parse \`git_branch\``" >&2