moved os-dependant code into per-os files
[guilt.git] / guilt-header
blob6227e5820ade99c6aa83a7e9d45d9c9d7f021449
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2010
6 USAGE="[-eE] [<patchname>]"
7 . `dirname $0`/guilt
9 case $# in
11 patch=`get_top`
14 if [ "$1" = "-e" ]; then
15 edit=t
16 patch=`get_top`
17 elif [ "$1" = "-E" ]; then
18 edit=t
19 full=t
20 patch=`get_top`
21 else
22 patch="$1"
26 if [ "$1" = "-e" ]; then
27 edit=t
28 patch="$2"
29 elif [ "$1" = "-E" ]; then
30 edit=t
31 full=t
32 patch="$2"
33 else
34 usage
37 esac
39 # are there any patches applied?
40 [ -z "$patch" ] && die "No patches applied."
42 # check that patch exists in the series
43 ret=`get_full_series | grep -e "^$patch\$" | wc -l`
44 if [ $ret -eq 0 ]; then
45 die "Patch $patch is not in the series"
48 # FIXME: warn if we're editing an applied patch
50 TMP_MSG=`get_tmp_file msg`
51 TMP_DIFF=`get_tmp_file diff`
53 if [ -z "$edit" ]; then
54 do_get_header "$GUILT_DIR/$branch/$patch"
55 else
56 if [ -n "$full" ]; then
57 git_editor "$GUILT_DIR/$branch/$patch"
58 exit $?
60 do_get_full_header "$GUILT_DIR/$branch/$patch" > "$TMP_MSG"
61 do_get_patch "$GUILT_DIR/$branch/$patch" > "$TMP_DIFF"
62 git_editor "$TMP_MSG"
63 mv "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$patch~"
66 cat "$TMP_MSG"
67 cat "$TMP_DIFF"
68 ) > "$GUILT_DIR/$branch/$patch"
71 rm -f "$TMP_MSG" "$TMP_DIFF"