doc: git doesn't use git-foo invocations.
[guilt.git] / guilt-header
blobc3d24f99d0e11de1fe979d67ddfd92a63a7b1c7f
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2013
6 USAGE="[-eE] [<patchname>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 case $# in
16 patch=`get_top`
19 if [ "$1" = "-e" ]; then
20 edit=t
21 patch=`get_top`
22 elif [ "$1" = "-E" ]; then
23 edit=t
24 full=t
25 patch=`get_top`
26 else
27 patch="$1"
31 if [ "$1" = "-e" ]; then
32 edit=t
33 patch="$2"
34 elif [ "$1" = "-E" ]; then
35 edit=t
36 full=t
37 patch="$2"
38 else
39 usage
42 esac
44 # are there any patches applied?
45 [ -z "$patch" ] && die "No patches applied."
47 # check that patch exists in the series
48 TMP_FULL_SERIES=`get_tmp_file series`
49 get_full_series > "$TMP_FULL_SERIES"
50 found_patch=
51 while read x; do
52 if [ "$x" = "$patch" ]; then
53 found_patch="$patch"
54 break
56 done < "$TMP_FULL_SERIES"
57 if [ -z "$found_patch" ]; then
58 TMP_MATCHES=`get_tmp_file series`
59 grep "$patch" < "$TMP_FULL_SERIES" > "$TMP_MATCHES"
60 nr=`wc -l < $TMP_MATCHES`
61 if [ $nr -gt 1 ]; then
62 echo "$patch does not uniquely identify a patch. Did you mean any of these?" >&2
63 sed 's/^/ /' "$TMP_MATCHES" >&2
64 rm -f "$TMP_MATCHES" "$TMP_FULL_SERIES"
65 exit 1
66 elif [ $nr -eq 0 ]; then
67 rm -f "$TMP_MATCHES" "$TMP_FULL_SERIES"
68 die "Patch $patch is not in the series"
70 found_patch=`cat $TMP_MATCHES`
71 rm -f "$TMP_MATCHES"
73 rm -f "$TMP_FULL_SERIES"
74 patch="$found_patch"
76 # FIXME: warn if we're editing an applied patch
78 TMP_MSG=`get_tmp_file msg`
79 TMP_DIFF=`get_tmp_file diff`
81 if [ -z "$edit" ]; then
82 do_get_header "$GUILT_DIR/$branch/$patch"
83 else
84 if [ -n "$full" ]; then
85 git_editor "$GUILT_DIR/$branch/$patch"
86 exit $?
88 do_get_full_header "$GUILT_DIR/$branch/$patch" > "$TMP_MSG"
89 do_get_patch "$GUILT_DIR/$branch/$patch" > "$TMP_DIFF"
90 git_editor "$TMP_MSG"
91 mv "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$patch~"
94 cat "$TMP_MSG"
95 cat "$TMP_DIFF"
96 ) > "$GUILT_DIR/$branch/$patch"
99 rm -f "$TMP_MSG" "$TMP_DIFF"