Code

Merge git://git.kernel.org/pub/scm/gitk/gitk
[git.git] / git-commit.sh
index 05828bb113d715a1067838ed2ac58ad8db06bf34..e23918cd6c515e193d3bc5d476c360001fdc1222 100755 (executable)
@@ -6,9 +6,9 @@
 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
+require_work_tree
 
 git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
-branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
 
 case "$0" in
 *status)
@@ -80,6 +80,7 @@ no_edit=
 log_given=
 log_message=
 verify=t
+quiet=
 verbose=
 signoff=
 force_author=
@@ -241,6 +242,10 @@ $1"
                signoff=t
                shift
                ;;
+       -q|--q|--qu|--qui|--quie|--quiet)
+               quiet=t
+               shift
+               ;;
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
                verbose=t
                shift
@@ -311,22 +316,16 @@ esac
 ################################################################
 # Prepare index to have a tree to be committed
 
-TOP=`git-rev-parse --show-cdup`
-if test -z "$TOP"
-then
-       TOP=./
-fi
-
 case "$all,$also" in
 t,)
        save_index &&
        (
-               cd "$TOP"
-               GIT_INDEX_FILE="$NEXT_INDEX"
-               export GIT_INDEX_FILE
+               cd_to_toplevel &&
+               GIT_INDEX_FILE="$NEXT_INDEX" &&
+               export GIT_INDEX_FILE &&
                git-diff-files --name-only -z |
                git-update-index --remove -z --stdin
-       )
+       ) || exit
        ;;
 ,t)
        save_index &&
@@ -334,11 +333,11 @@ t,)
 
        git-diff-files --name-only -z -- "$@"  |
        (
-               cd "$TOP"
-               GIT_INDEX_FILE="$NEXT_INDEX"
-               export GIT_INDEX_FILE
+               cd_to_toplevel &&
+               GIT_INDEX_FILE="$NEXT_INDEX" &&
+               export GIT_INDEX_FILE &&
                git-update-index --remove -z --stdin
-       )
+       ) || exit
        ;;
 ,)
        case "$#" in
@@ -430,7 +429,9 @@ then
        fi
 elif test "$use_commit" != ""
 then
-       git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
+       encoding=$(git repo-config i18n.commitencoding || echo UTF-8)
+       git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
+       sed -e '1,/^$/d' -e 's/^    //'
 elif test -f "$GIT_DIR/MERGE_MSG"
 then
        cat "$GIT_DIR/MERGE_MSG"
@@ -492,7 +493,8 @@ then
                q
        }
        '
-       set_author_env=`git-cat-file commit "$use_commit" |
+       encoding=$(git repo-config i18n.commitencoding || echo UTF-8)
+       set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
        LANG=C LC_ALL=C sed -ne "$pick_author_script"`
        eval "$set_author_env"
        export GIT_AUTHOR_NAME
@@ -515,7 +517,7 @@ then
        current="$(git-rev-parse --verify HEAD)"
 else
        if [ -z "$(git-ls-files)" ]; then
-               echo >&2 Nothing to commit
+               echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
                exit 1
        fi
        PARENTS=""
@@ -615,11 +617,17 @@ then
        git-rerere
 fi
 
-if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
+if test "$ret" = 0
 then
-       "$GIT_DIR"/hooks/post-commit
+       if test -x "$GIT_DIR"/hooks/post-commit
+       then
+               "$GIT_DIR"/hooks/post-commit
+       fi
+       if test -z "$quiet"
+       then
+               echo "Created${initial_commit:+ initial} commit $commit"
+               git-diff-tree --shortstat --summary --root --no-commit-id HEAD --
+       fi
 fi
 
-test "$ret" = 0 && git-diff-tree --summary --root --no-commit-id HEAD
-
 exit "$ret"