Code

Fix off-by-one in read_tree_recursive
[git.git] / git-pull.sh
index 809e537a4d81233966aad23df11c13931d6250c1..c8920596050abc531d721dc95dfc8b11096ecd92 100755 (executable)
@@ -16,13 +16,17 @@ cd_to_toplevel
 test -z "$(git ls-files -u)" ||
        die "You are in the middle of a conflicted merge."
 
-strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
+strategy_args= no_stat= no_commit= squash= no_ff= log_arg= verbosity=
 curr_branch=$(git symbolic-ref -q HEAD)
 curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
 rebase=$(git config --bool branch.$curr_branch_short.rebase)
 while :
 do
        case "$1" in
+       -q|--quiet)
+               verbosity="$verbosity -q" ;;
+       -v|--verbose)
+               verbosity="$verbosity -v" ;;
        -n|--no-stat|--no-summary)
                no_stat=-n ;;
        --stat|--summary)
@@ -86,30 +90,38 @@ error_on_no_merge_candidates () {
 
        curr_branch=${curr_branch#refs/heads/}
 
-       echo "You asked me to pull without telling me which branch you"
-       echo "want to merge with, and 'branch.${curr_branch}.merge' in"
-       echo "your configuration file does not tell me either.  Please"
-       echo "name which branch you want to merge on the command line and"
-       echo "try again (e.g. 'git pull <repository> <refspec>')."
-       echo "See git-pull(1) for details on the refspec."
-       echo
-       echo "If you often merge with the same branch, you may want to"
-       echo "configure the following variables in your configuration"
-       echo "file:"
-       echo
-       echo "    branch.${curr_branch}.remote = <nickname>"
-       echo "    branch.${curr_branch}.merge = <remote-ref>"
-       echo "    remote.<nickname>.url = <url>"
-       echo "    remote.<nickname>.fetch = <refspec>"
-       echo
-       echo "See git-config(1) for details."
+       if [ -z "$curr_branch" ]; then
+               echo "You are not currently on a branch, so I cannot use any"
+               echo "'branch.<branchname>.merge' in your configuration file."
+               echo "Please specify which branch you want to merge on the command"
+               echo "line and try again (e.g. 'git pull <repository> <refspec>')."
+               echo "See git-pull(1) for details."
+       else
+               echo "You asked me to pull without telling me which branch you"
+               echo "want to merge with, and 'branch.${curr_branch}.merge' in"
+               echo "your configuration file does not tell me either.  Please"
+               echo "specify which branch you want to merge on the command line and"
+               echo "try again (e.g. 'git pull <repository> <refspec>')."
+               echo "See git-pull(1) for details."
+               echo
+               echo "If you often merge with the same branch, you may want to"
+               echo "configure the following variables in your configuration"
+               echo "file:"
+               echo
+               echo "    branch.${curr_branch}.remote = <nickname>"
+               echo "    branch.${curr_branch}.merge = <remote-ref>"
+               echo "    remote.<nickname>.url = <url>"
+               echo "    remote.<nickname>.fetch = <refspec>"
+               echo
+               echo "See git-config(1) for details."
+       fi
        exit 1
 }
 
 test true = "$rebase" && {
-       git update-index --refresh &&
-       git diff-files --quiet &&
-       git diff-index --cached --quiet HEAD -- ||
+       git update-index --ignore-submodules --refresh &&
+       git diff-files --ignore-submodules --quiet &&
+       git diff-index --ignore-submodules --cached --quiet HEAD -- ||
        die "refusing to pull with rebase: your working tree is not up-to-date"
 
        . git-parse-remote &&
@@ -117,14 +129,14 @@ test true = "$rebase" && {
        test -z "$origin" && origin=$(get_default_remote)
        reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null |
                sed "s|refs/heads/\(.*\):|\1|")" &&
-       oldremoteref="$(git rev-parse --verify \
-               "refs/remotes/$origin/$reflist" 2>/dev/null)"
+       oldremoteref="$(git rev-parse -q --verify \
+               "refs/remotes/$origin/$reflist")"
 }
-orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
-git-fetch --update-head-ok "$@" || exit 1
+orig_head=$(git rev-parse -q --verify HEAD)
+git fetch $verbosity --update-head-ok "$@" || exit 1
 
-curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
-if test "$curr_head" != "$orig_head"
+curr_head=$(git rev-parse -q --verify HEAD)
+if test -n "$orig_head" && test "$curr_head" != "$orig_head"
 then
        # The fetch involved updating the current branch.
 
@@ -167,12 +179,17 @@ case "$merge_head" in
                echo >&2 "Cannot merge multiple branches into empty head"
                exit 1
        fi
+       if test true = "$rebase"
+       then
+               echo >&2 "Cannot rebase onto multiple branches"
+               exit 1
+       fi
        ;;
 esac
 
 if test -z "$orig_head"
 then
-       git update-ref -m "initial pull" HEAD $merge_head "" &&
+       git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
        git read-tree --reset -u HEAD || exit 1
        exit
 fi
@@ -182,4 +199,4 @@ test true = "$rebase" &&
        exec git-rebase $strategy_args --onto $merge_head \
        ${oldremoteref:-$merge_head}
 exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \
-       "$merge_name" HEAD $merge_head
+       "$merge_name" HEAD $merge_head $verbosity