Merge branch 'us/printf-not-echo'
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Mar 2014 18:08:26 +0000 (11:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Mar 2014 18:08:27 +0000 (11:08 -0700)
* us/printf-not-echo:
test-lib.sh: do not "echo" caller-supplied strings
rebase -i: do not "echo" random user-supplied strings

1  2 
git-rebase--interactive.sh
t/test-lib.sh
index a1adae83131b5918ec6f994043f3f3ccd3b8c3d8,43631b472311d0feb13f4d62c6355baeedbdb040..1c41cbd66c77641772c41898362b7fc550c4faca
@@@ -179,10 -179,9 +179,10 @@@ exit_with_patch () 
        echo "$1" > "$state_dir"/stopped-sha
        make_patch $1
        git rev-parse --verify HEAD > "$amend"
 +      gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
        warn "You can amend the commit now, with"
        warn
 -      warn "  git commit --amend"
 +      warn "  git commit --amend $gpg_sign_opt_quoted"
        warn
        warn "Once you are satisfied with your changes, run"
        warn
@@@ -249,9 -248,7 +249,9 @@@ pick_one () 
  
        test -d "$rewritten" &&
                pick_one_preserving_merges "$@" && return
 -      output eval git cherry-pick "$strategy_args" $empty_args $ff "$@"
 +      output eval git cherry-pick \
 +                      ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
 +                      "$strategy_args" $empty_args $ff "$@"
  }
  
  pick_one_preserving_merges () {
                        new_parents=${new_parents# $first_parent}
                        merge_args="--no-log --no-ff"
                        if ! do_with_author output eval \
 -                      'git merge $merge_args $strategy_args -m "$msg_content" $new_parents'
 +                      'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
 +                              $merge_args $strategy_args -m "$msg_content" $new_parents'
                        then
                                printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
                                die_with_patch $sha1 "Error redoing merge $sha1"
                        echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
                        ;;
                *)
 -                      output eval git cherry-pick "$strategy_args" "$@" ||
 +                      output eval git cherry-pick \
 +                              ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
 +                              "$strategy_args" "$@" ||
                                die_with_patch $sha1 "Could not pick $sha1"
                        ;;
                esac
@@@ -476,8 -470,7 +476,8 @@@ do_pick () 
                           --no-post-rewrite -n -q -C $1 &&
                        pick_one -n $1 &&
                        git commit --allow-empty --allow-empty-message \
 -                                 --amend --no-post-rewrite -n -q -C $1 ||
 +                                 --amend --no-post-rewrite -n -q -C $1 \
 +                                 ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                        die_with_patch $1 "Could not apply $1... $2"
        else
                pick_one $1 ||
@@@ -504,7 -497,7 +504,7 @@@ do_next () 
  
                mark_action_done
                do_pick $sha1 "$rest"
 -              git commit --amend --no-post-rewrite || {
 +              git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
                        warn "Could not amend commit after successfully picking $sha1... $rest"
                        warn "This is most likely due to an empty commit message, or the pre-commit hook"
                        warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
                squash|s|fixup|f)
                        # This is an intermediate commit; its message will only be
                        # used in case of trouble.  So use the long version:
 -                      do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
 +                      do_with_author output git commit --amend --no-verify -F "$squash_msg" \
 +                              ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                die_failed_squash $sha1 "$rest"
                        ;;
                *)
                        # This is the final command of this squash/fixup group
                        if test -f "$fixup_msg"
                        then
 -                              do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
 +                              do_with_author git commit --amend --no-verify -F "$fixup_msg" \
 +                                      ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                        die_failed_squash $sha1 "$rest"
                        else
                                cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
                                rm -f "$GIT_DIR"/MERGE_MSG
 -                              do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
 +                              do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
 +                                      ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                        die_failed_squash $sha1 "$rest"
                        fi
                        rm -f "$squash_msg" "$fixup_msg"
@@@ -749,7 -739,7 +749,7 @@@ rearrange_squash () 
                                        ;;
                                esac
                        done
-                       echo "$sha1 $action $prefix $rest"
+                       printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
                        # if it's a single word, try to resolve to a full sha1 and
                        # emit a second copy. This allows us to match on both message
                        # and on sha1 prefix
@@@ -829,15 -819,14 +829,15 @@@ continue
        else
                if ! test -f "$author_script"
                then
 +                      gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
                        die "You have staged changes in your working tree. If these changes are meant to be
  squashed into the previous commit, run:
  
 -  git commit --amend
 +  git commit --amend $gpg_sign_opt_quoted
  
  If they are meant to go into a new commit, run:
  
 -  git commit
 +  git commit $gpg_sign_opt_quoted
  
  In both case, once you're done, continue with:
  
                        die "\
  You have uncommitted changes in your working tree. Please, commit them
  first and then run 'git rebase --continue' again."
 -                      do_with_author git commit --amend --no-verify -F "$msg" -e ||
 +                      do_with_author git commit --amend --no-verify -F "$msg" -e \
 +                              ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                die "Could not commit staged changes."
                else
 -                      do_with_author git commit --no-verify -F "$msg" -e ||
 +                      do_with_author git commit --no-verify -F "$msg" -e \
 +                              ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                die "Could not commit staged changes."
                fi
        fi
diff --combined t/test-lib.sh
index 569b52dc0fa32f48f37dc0d29771118cc624c5e7,3c7cb1d774cadaa4d625e2d53ba122db4108cb0e..87f327ff8bcd2c2a29fcbabe74c226232b54f728
@@@ -108,12 -108,6 +108,12 @@@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAM
  export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
  export EDITOR
  
 +if test -n "${TEST_GIT_INDEX_VERSION:+isset}"
 +then
 +      GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION"
 +      export GIT_INDEX_VERSION
 +fi
 +
  # Add libc MALLOC and MALLOC_PERTURB test
  # only if we are not executing the test with valgrind
  if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null ||
@@@ -283,7 -277,7 +283,7 @@@ error "Test script did not set test_des
  
  if test "$help" = "t"
  then
-       echo "$test_description"
+       printf '%s\n' "$test_description"
        exit 0
  fi
  
@@@ -334,7 -328,7 +334,7 @@@ test_failure_ () 
        test_failure=$(($test_failure + 1))
        say_color error "not ok $test_count - $1"
        shift
-       echo "$@" | sed -e 's/^/#       /'
+       printf '%s\n' "$*" | sed -e 's/^/#      /'
        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
  }