Merge branch 'eb/mailinfo'
[git.git] / git-commit.sh
index c9c22ab..1983d45 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2006 Junio C Hamano
 
-USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>) [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
+USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 
@@ -134,13 +134,17 @@ run_status () {
        report "Changed but not updated" \
            "use git-update-index to mark for commit"
 
+        option=""
+        if test -z "$untracked_files"; then
+            option="--directory --no-empty-directory"
+        fi
        if test -f "$GIT_DIR/info/exclude"
        then
-           git-ls-files -z --others --directory \
+           git-ls-files -z --others $option \
                --exclude-from="$GIT_DIR/info/exclude" \
                --exclude-per-directory=.gitignore
        else
-           git-ls-files -z --others --directory \
+           git-ls-files -z --others $option \
                --exclude-per-directory=.gitignore
        fi |
        perl -e '$/ = "\0";
@@ -161,14 +165,19 @@ run_status () {
            }
        '
 
-       if test -n "$verbose"
+       if test -n "$verbose" -a -z "$IS_INITIAL"
        then
            git-diff-index --cached -M -p --diff-filter=MDTCRA $REFERENCE
        fi
        case "$committable" in
        0)
-           echo "nothing to commit"
-           exit 1
+               case "$amend" in
+               t)
+                       echo "# No changes" ;;
+               *)
+                       echo "nothing to commit" ;;
+               esac
+               exit 1 ;;
        esac
        exit 0
     )
@@ -198,6 +207,7 @@ verbose=
 signoff=
 force_author=
 only_include_assumed=
+untracked_files=
 while case "$#" in 0) break;; esac
 do
   case "$1" in
@@ -335,6 +345,12 @@ do
       verbose=t
       shift
       ;;
+  -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|--untracked|\
+  --untracked-|--untracked-f|--untracked-fi|--untracked-fil|--untracked-file|\
+  --untracked-files)
+      untracked_files=t
+      shift
+      ;;
   --)
       shift
       break
@@ -365,14 +381,16 @@ tt*)
   die "Only one of -c/-C/-F/-m can be used." ;;
 esac
 
-case "$#,$also$only" in
-*,tt)
+case "$#,$also,$only,$amend" in
+*,t,t,*)
   die "Only one of --include/--only can be used." ;;
-0,t)
+0,t,,* | 0,,t,)
   die "No paths with --include/--only does not make sense." ;;
-0,)
+0,,t,t)
+  only_include_assumed="# Clever... amending the last one with dirty index." ;;
+0,,,*)
   ;;
-*,)
+*,,,*)
   only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
   also=
   ;;
@@ -537,7 +555,7 @@ t)
        ;;
 esac
 
-if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
+if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
        echo "#"
        echo "# It looks like you may be committing a MERGE."
        echo "# If this is not correct, please remove the file"
@@ -549,8 +567,8 @@ fi >>"$GIT_DIR"/COMMIT_EDITMSG
 # Author
 if test '' != "$force_author"
 then
-       GIT_AUTHOR_NAME=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
-       GIT_AUTHOR_EMAIL=`expr "$force_author" : '.*\(<.*\)'` &&
+       GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
+       GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
        test '' != "$GIT_AUTHOR_NAME" &&
        test '' != "$GIT_AUTHOR_EMAIL" ||
        die "malformatted --author parameter"
@@ -595,24 +613,36 @@ then
                PARENTS=$(git-cat-file commit HEAD |
                        sed -n -e '/^$/q' -e 's/^parent /-p /p')
        fi
+       current=$(git-rev-parse --verify HEAD)
 else
        if [ -z "$(git-ls-files)" ]; then
                echo >&2 Nothing to commit
                exit 1
        fi
        PARENTS=""
+       current=
 fi
 
-{
-       test -z "$only_include_assumed" || echo "$only_include_assumed"
-       run_status
-} >>"$GIT_DIR"/COMMIT_EDITMSG
-if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
+if test -z "$no_edit"
+then
+       {
+               echo ""
+               echo "# Please enter the commit message for your changes."
+               echo "# (Comment lines starting with '#' will not be included)"
+               test -z "$only_include_assumed" || echo "$only_include_assumed"
+               run_status
+       } >>"$GIT_DIR"/COMMIT_EDITMSG
+else
+       # we need to check if there is anything to commit
+       run_status >/dev/null 
+fi
+if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
 then
        rm -f "$GIT_DIR/COMMIT_EDITMSG"
        run_status
        exit 1
 fi
+
 case "$no_edit" in
 '')
        case "${VISUAL:-$EDITOR},$TERM" in
@@ -624,6 +654,8 @@ case "$no_edit" in
                exit 1
                ;;
        esac
+       git-var GIT_AUTHOR_IDENT > /dev/null  || die
+       git-var GIT_COMMITTER_IDENT > /dev/null  || die
        ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
        ;;
 esac