X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-commit.sh;h=4cf3fab05cd3c3367173c86a65665ddfc1d89805;hb=3cd4f5e8eb04ae01298ceaf46bb41a4277031916;hp=1983d45828228750e9b2db337140a5c9e7c27bfa;hpb=d177e584255aad351bbbff14aba8e73afc008c75;p=git.git diff --git a/git-commit.sh b/git-commit.sh index 1983d4582..4cf3fab05 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -29,7 +29,7 @@ THIS_INDEX="$GIT_DIR/index" NEXT_INDEX="$GIT_DIR/next-index$$" rm -f "$NEXT_INDEX" save_index () { - cp "$THIS_INDEX" "$NEXT_INDEX" + cp -p "$THIS_INDEX" "$NEXT_INDEX" } report () { @@ -138,32 +138,26 @@ run_status () { if test -z "$untracked_files"; then option="--directory --no-empty-directory" fi + hdr_shown= if test -f "$GIT_DIR/info/exclude" then - git-ls-files -z --others $option \ + git-ls-files --others $option \ --exclude-from="$GIT_DIR/info/exclude" \ --exclude-per-directory=.gitignore else - git-ls-files -z --others $option \ + git-ls-files --others $option \ --exclude-per-directory=.gitignore fi | - perl -e '$/ = "\0"; - my $shown = 0; - while (<>) { - chomp; - s|\\|\\\\|g; - s|\t|\\t|g; - s|\n|\\n|g; - s/^/# /; - if (!$shown) { - print "#\n# Untracked files:\n"; - print "# (use \"git add\" to add to commit)\n"; - print "#\n"; - $shown = 1; - } - print "$_\n"; - } - ' + while read line; do + if [ -z "$hdr_shown" ]; then + echo '#' + echo '# Untracked files:' + echo '# (use "git add" to add to commit)' + echo '#' + hdr_shown=1 + fi + echo "# $line" + done if test -n "$verbose" -a -z "$IS_INITIAL" then @@ -199,6 +193,7 @@ only= logfile= use_commit= amend= +edit_flag= no_edit= log_given= log_message= @@ -222,13 +217,13 @@ do -F*|-f*) no_edit=t log_given=t$log_given - logfile=`expr "$1" : '-[Ff]\(.*\)'` + logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` shift ;; --F=*|--f=*|--fi=*|--fil=*|--file=*) no_edit=t log_given=t$log_given - logfile=`expr "$1" : '-[^=]*=\(.*\)'` + logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` shift ;; -a|--a|--al|--all) @@ -236,7 +231,7 @@ do shift ;; --au=*|--aut=*|--auth=*|--autho=*|--author=*) - force_author=`expr "$1" : '-[^=]*=\(.*\)'` + force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` shift ;; --au|--aut|--auth|--autho|--author) @@ -246,7 +241,7 @@ do shift ;; -e|--e|--ed|--edi|--edit) - no_edit= + edit_flag=t shift ;; -i|--i|--in|--inc|--incl|--inclu|--includ|--include) @@ -260,20 +255,41 @@ do -m|--m|--me|--mes|--mess|--messa|--messag|--message) case "$#" in 1) usage ;; esac shift - log_given=t$log_given - log_message="$1" + log_given=m$log_given + if test "$log_message" = '' + then + log_message="$1" + else + log_message="$log_message + +$1" + fi no_edit=t shift ;; -m*) - log_given=t$log_given - log_message=`expr "$1" : '-m\(.*\)'` + log_given=m$log_given + if test "$log_message" = '' + then + log_message=`expr "z$1" : 'z-m\(.*\)'` + else + log_message="$log_message + +`expr "z$1" : 'z-m\(.*\)'`" + fi no_edit=t shift ;; --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) - log_given=t$log_given - log_message=`expr "$1" : '-[^=]*=\(.*\)'` + log_given=m$log_given + if test "$log_message" = '' + then + log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` + else + log_message="$log_message + +`expr "z$1" : 'zq-[^=]*=\(.*\)'`" + fi no_edit=t shift ;; @@ -299,7 +315,7 @@ do --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ --reedit-messag=*|--reedit-message=*) log_given=t$log_given - use_commit=`expr "$1" : '-[^=]*=\(.*\)'` + use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` no_edit= shift ;; @@ -324,7 +340,7 @@ do --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ --reuse-message=*) log_given=t$log_given - use_commit=`expr "$1" : '-[^=]*=\(.*\)'` + use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` no_edit=t shift ;; @@ -363,6 +379,7 @@ do ;; esac done +case "$edit_flag" in t) no_edit= ;; esac ################################################################ # Sanity check options @@ -378,7 +395,9 @@ esac case "$log_given" in tt*) - die "Only one of -c/-C/-F/-m can be used." ;; + die "Only one of -c/-C/-F can be used." ;; +*tm*|*mt*) + die "Option -m cannot be combined with -c/-C/-F." ;; esac case "$#,$also,$only,$amend" in @@ -541,6 +560,9 @@ then elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG" then cat "$GIT_DIR/MERGE_MSG" +elif test -f "$GIT_DIR/SQUASH_MSG" +then + cat "$GIT_DIR/SQUASH_MSG" fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG case "$signoff" in @@ -571,7 +593,7 @@ then GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && test '' != "$GIT_AUTHOR_NAME" && test '' != "$GIT_AUTHOR_EMAIL" || - die "malformatted --author parameter" + die "malformed --author parameter" export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL elif test '' != "$use_commit" then @@ -607,9 +629,12 @@ fi PARENTS="-p HEAD" if test -z "$initial_commit" then + rloga='commit' if [ -f "$GIT_DIR/MERGE_HEAD" ]; then + rloga='commit (merge)' PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` elif test -n "$amend"; then + rloga='commit (amend)' PARENTS=$(git-cat-file commit HEAD | sed -n -e '/^$/q' -e 's/^parent /-p /p') fi @@ -621,6 +646,7 @@ else fi PARENTS="" current= + rloga='commit (initial)' fi if test -z "$no_edit" @@ -638,7 +664,7 @@ else fi if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] then - rm -f "$GIT_DIR/COMMIT_EDITMSG" + rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" run_status exit 1 fi @@ -668,13 +694,18 @@ t) fi esac -sed -e ' - /^diff --git a\/.*/{ - s/// - q - } - /^#/d -' "$GIT_DIR"/COMMIT_EDITMSG | +if test -z "$no_edit" +then + sed -e ' + /^diff --git a\/.*/{ + s/// + q + } + /^#/d + ' "$GIT_DIR"/COMMIT_EDITMSG +else + cat "$GIT_DIR"/COMMIT_EDITMSG +fi | git-stripspace >"$GIT_DIR"/COMMIT_MSG if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | @@ -690,7 +721,8 @@ then rm -f "$TMP_INDEX" fi && commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) && - git-update-ref HEAD $commit $current && + rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && + git-update-ref -m "$rloga: $rlogm" HEAD $commit $current && rm -f -- "$GIT_DIR/MERGE_HEAD" && if test -f "$NEXT_INDEX" then @@ -703,7 +735,7 @@ else false fi ret="$?" -rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" +rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" if test -d "$GIT_DIR/rr-cache" then git-rerere