Merge branch 'bs/maint-commit-options'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2007 22:25:46 +0000 (14:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2007 22:25:46 +0000 (14:25 -0800)
* bs/maint-commit-options:
  git-commit: Add tests for invalid usage of -a/--interactive with paths
  git-commit.sh: Fix usage checks regarding paths given when they do not make sense

1  2 
git-commit.sh
t/t7501-commit.sh

diff --combined git-commit.sh
@@@ -26,7 -26,7 +26,7 @@@ refuse_partial () 
  }
  
  TMP_INDEX=
 -THIS_INDEX="$GIT_DIR/index"
 +THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
  NEXT_INDEX="$GIT_DIR/next-index$$"
  rm -f "$NEXT_INDEX"
  save_index () {
@@@ -99,71 -99,101 +99,71 @@@ d
                no_edit=t
                log_given=t$log_given
                logfile="$1"
 -              shift
                ;;
        -F*|-f*)
                no_edit=t
                log_given=t$log_given
 -              logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
 -              shift
 +              logfile="${1#-[Ff]}"
                ;;
        --F=*|--f=*|--fi=*|--fil=*|--file=*)
                no_edit=t
                log_given=t$log_given
 -              logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 -              shift
 +              logfile="${1#*=}"
                ;;
        -a|--a|--al|--all)
                all=t
 -              shift
                ;;
        --au=*|--aut=*|--auth=*|--autho=*|--author=*)
 -              force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 -              shift
 +              force_author="${1#*=}"
                ;;
        --au|--aut|--auth|--autho|--author)
                case "$#" in 1) usage ;; esac
                shift
                force_author="$1"
 -              shift
                ;;
        -e|--e|--ed|--edi|--edit)
                edit_flag=t
 -              shift
                ;;
        -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
                also=t
 -              shift
                ;;
        --int|--inte|--inter|--intera|--interac|--interact|--interacti|\
        --interactiv|--interactive)
                interactive=t
 -              shift
                ;;
        -o|--o|--on|--onl|--only)
                only=t
 -              shift
                ;;
        -m|--m|--me|--mes|--mess|--messa|--messag|--message)
                case "$#" in 1) usage ;; esac
                shift
                log_given=m$log_given
 -              if test "$log_message" = ''
 -              then
 -                  log_message="$1"
 -              else
 -                  log_message="$log_message
 +              log_message="${log_message:+${log_message}
  
 -$1"
 -              fi
 +}$1"
                no_edit=t
 -              shift
                ;;
        -m*)
                log_given=m$log_given
 -              if test "$log_message" = ''
 -              then
 -                  log_message=`expr "z$1" : 'z-m\(.*\)'`
 -              else
 -                  log_message="$log_message
 +              log_message="${log_message:+${log_message}
  
 -`expr "z$1" : 'z-m\(.*\)'`"
 -              fi
 +}${1#-m}"
                no_edit=t
 -              shift
                ;;
        --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
                log_given=m$log_given
 -              if test "$log_message" = ''
 -              then
 -                  log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 -              else
 -                  log_message="$log_message
 +              log_message="${log_message:+${log_message}
  
 -`expr "z$1" : 'zq-[^=]*=\(.*\)'`"
 -              fi
 +}${1#*=}"
                no_edit=t
 -              shift
                ;;
        -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
        --no-verify)
                verify=
 -              shift
                ;;
        --a|--am|--ame|--amen|--amend)
                amend=t
                use_commit=HEAD
 -              shift
                ;;
        -c)
                case "$#" in 1) usage ;; esac
                log_given=t$log_given
                use_commit="$1"
                no_edit=
 -              shift
                ;;
        --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
        --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
        --reedit-messag=*|--reedit-message=*)
                log_given=t$log_given
 -              use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 +              use_commit="${1#*=}"
                no_edit=
 -              shift
                ;;
        --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
        --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
                log_given=t$log_given
                use_commit="$1"
                no_edit=
 -              shift
                ;;
        -C)
                case "$#" in 1) usage ;; esac
                log_given=t$log_given
                use_commit="$1"
                no_edit=t
 -              shift
                ;;
        --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
        --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
        --reuse-message=*)
                log_given=t$log_given
 -              use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 +              use_commit="${1#*=}"
                no_edit=t
 -              shift
                ;;
        --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
        --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
                log_given=t$log_given
                use_commit="$1"
                no_edit=t
 -              shift
                ;;
        -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
                signoff=t
 -              shift
                ;;
        -t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)
                case "$#" in 1) usage ;; esac
                shift
                templatefile="$1"
                no_edit=
 -              shift
                ;;
        -q|--q|--qu|--qui|--quie|--quiet)
                quiet=t
 -              shift
                ;;
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
                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
                ;;
        esac
 +      shift
  done
  case "$edit_flag" in t) no_edit= ;; esac
  
@@@ -282,9 -322,9 +282,9 @@@ unset onl
  case "$all,$interactive,$also,$#" in
  *t,*t,*)
        die "Cannot use -a, --interactive or -i at the same time." ;;
- t,,[1-9]*)
+ t,,,[1-9]*)
        die "Paths with -a does not make sense." ;;
- ,t,[1-9]*)
+ ,t,,[1-9]*)
        die "Paths with --interactive does not make sense." ;;
  ,,t,0)
        die "No paths with -i does not make sense." ;;
@@@ -402,8 -442,12 +402,8 @@@ esa
  
  if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
  then
 -      if test "$TMP_INDEX"
 -      then
 -              GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
 -      else
 -              GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
 -      fi || exit
 +    GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \
 +    || exit
  fi
  
  if test "$log_message" != ''
@@@ -612,7 -656,6 +612,7 @@@ git rerer
  
  if test "$ret" = 0
  then
 +      git gc --auto
        if test -x "$GIT_DIR"/hooks/post-commit
        then
                "$GIT_DIR"/hooks/post-commit
diff --combined t/t7501-commit.sh
@@@ -33,6 -33,16 +33,16 @@@ test_expect_failure 
        "invalid options 2" \
        "git-commit -C HEAD -m illegal"
  
+ test_expect_failure \
+       "using paths with -a" \
+       "echo King of the bongo >file &&
+       git-commit -m foo -a file"
+ test_expect_failure \
+       "using paths with --interactive" \
+       "echo bong-o-bong >file &&
+       echo 7 | git-commit -m foo --interactive file"
  test_expect_failure \
        "using invalid commit with -C" \
        "git-commit -C bogus"
@@@ -163,73 -173,4 +173,73 @@@ test_expect_success 'partial commit tha
  
  '
  
 +author="The Real Author <someguy@his.email.org>"
 +test_expect_success 'amend commit to fix author' '
 +
 +      oldtick=$GIT_AUTHOR_DATE &&
 +      test_tick &&
 +      git reset --hard &&
 +      git cat-file -p HEAD |
 +      sed -e "s/author.*/author $author $oldtick/" \
 +              -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
 +              expected &&
 +      git commit --amend --author="$author" &&
 +      git cat-file -p HEAD > current &&
 +      diff expected current
 +
 +'
 +
 +test_expect_success 'sign off (1)' '
 +
 +      echo 1 >positive &&
 +      git add positive &&
 +      git commit -s -m "thank you" &&
 +      git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 +      (
 +              echo thank you
 +              echo
 +              git var GIT_COMMITTER_IDENT |
 +              sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
 +      ) >expected &&
 +      diff -u expected actual
 +
 +'
 +
 +test_expect_success 'sign off (2)' '
 +
 +      echo 2 >positive &&
 +      git add positive &&
 +      existing="Signed-off-by: Watch This <watchthis@example.com>" &&
 +      git commit -s -m "thank you
 +
 +$existing" &&
 +      git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 +      (
 +              echo thank you
 +              echo
 +              echo $existing
 +              git var GIT_COMMITTER_IDENT |
 +              sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
 +      ) >expected &&
 +      diff -u expected actual
 +
 +'
 +
 +test_expect_success 'multiple -m' '
 +
 +      >negative &&
 +      git add negative &&
 +      git commit -m "one" -m "two" -m "three" &&
 +      git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 +      (
 +              echo one
 +              echo
 +              echo two
 +              echo
 +              echo three
 +      ) >expected &&
 +      diff -u expected actual
 +
 +'
 +
  test_done