[PATCH] guilt-refresh: Check color.ui git config before refresh
[guilt.git] / guilt-new
blob9f7fa44e753556cb45d650d7f5c3edab25924115
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2013
6 USAGE="[-f] [-s] [-e|-m message] <patchname>"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 while [ $# -gt 0 ] ; do
15 case "$1" in
16 -f)
17 force=t
19 -s)
20 signoff=t
22 -e)
23 edit=t
25 if [ ! -z "$msg" ]; then
26 usage
29 -m)
30 if [ $# -eq 1 ]; then
31 usage
33 msg="$2"
34 shift
36 if [ ! -z "$edit" ]; then
37 usage
41 if [ ! -z "$patch" ]; then
42 usage
44 patch="$1"
46 esac
47 shift
48 done
50 if [ -z "$patch" ]; then
51 die "You must specify a patch name"
54 if [ -f "$GUILT_DIR/$branch/$patch" ]; then
55 die "patch '$patch' already exist"
58 iidx=`wc -l < "$applied"`
60 # make sure that there are no unapplied changes
61 if [ -z "$force" ] && ! must_commit_first; then
62 die "Uncommited changes detected. Refresh first."
65 if ! valid_patchname "$patch"; then
66 disp "Patchname is invalid." >&2
67 die "It must follow the rules in git-check-ref-format(1)."
70 # create any directories as needed
71 mkdir_dir=`dirname "$GUILT_DIR/$branch/$patch"`
72 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
74 # create the file with the right contents
76 # did we get a message with -m ?
77 [ ! -z "$msg" ] && printf "$msg\n\n"
79 # add a sign-off-by (-s)
80 [ "$signoff" = "t" ] && printf "Signed-off-by: `git var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`\n\n"
81 ) >> "$GUILT_DIR/$branch/$patch"
83 # edit -e ?
84 [ "$edit" = "t" ] && git_editor "$GUILT_DIR/$branch/$patch"
86 if [ ! -z "$force" ]; then
88 cd_to_toplevel
89 git diff --binary HEAD >> "$GUILT_DIR/$branch/$patch"
93 # insert the patch name into the series file
94 series_insert_patch "$patch"
96 # apply the patch
97 echo "$patch" >> "$applied"
98 commit "$patch" HEAD