test suite: remove pointless redirection.
[guilt.git] / guilt-import-commit
blobf14647c6710aa3a2c789c5eb6c92ffcf9c0bca85
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 --pretty=oneline -1 $rev | cut -c 42-`
31 fname=`echo $s | sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \
32 -e "s/['\\[{}]//g" -e 's/]//g' -e 's/\*/-/g' \
33 -e 's/\?/-/g' | tr A-Z a-z`
35 disp "Converting `echo $rev | cut -c 1-8` as $fname"
37 mangle_prefix=1
38 fname_base=$fname
39 while [ -f "$GUILT_DIR/$branch/$fname" ]; do
40 fname="$fname_base-$mangle_prefix"
41 mangle_prefix=`expr $mangle_prefix + 1`
42 disp "Patch under that name exists...trying '$fname'"
43 done
46 do_make_header $rev
47 echo ""
48 git diff --binary $rev^..$rev
49 ) > "$GUILT_DIR/$branch/$fname"
51 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
52 # timestamp on the patch
54 # insert the patch name into the series file
55 series_insert_patch $fname
57 # Only reset if the commit was on this branch
58 if head_check $rev 2> /dev/null; then
59 # BEWARE: "git reset" ahead! Is there a way to verify that
60 # we really created a patch? - We don't want to lose any
61 # history.
62 git reset --hard $rev^ > /dev/null
63 elif [ -z "$warned" ]; then
64 disp "Warning: commit $rev is not the HEAD...preserving commit" >&2
65 disp "Warning: (this message is displayed only once)" >&2
66 warned=t
68 done
70 disp "Done." >&2
71 disp "Current head: `git rev-parse \`git_branch\``" >&2