git-pull.shon commit git.el: Don't use --info-only when resolving a file. (cdc0873)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5# Fetch one or more remote refs and merge it/them into the current HEAD.
   6
   7USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
   8LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
   9. git-sh-setup
  10set_reflog_action "pull $*"
  11
  12test -z "$(git ls-files -u)" ||
  13        die "You are in a middle of conflicted merge."
  14
  15strategy_args= no_summary= no_commit= squash=
  16while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
  17do
  18        case "$1" in
  19        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
  20                --no-summa|--no-summar|--no-summary)
  21                no_summary=-n ;;
  22        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
  23                no_commit=--no-commit ;;
  24        --sq|--squ|--squa|--squas|--squash)
  25                squash=--squash ;;
  26        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
  27                --strateg=*|--strategy=*|\
  28        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
  29                case "$#,$1" in
  30                *,*=*)
  31                        strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
  32                1,*)
  33                        usage ;;
  34                *)
  35                        strategy="$2"
  36                        shift ;;
  37                esac
  38                strategy_args="${strategy_args}-s $strategy "
  39                ;;
  40        -h|--h|--he|--hel|--help)
  41                usage
  42                ;;
  43        -*)
  44                # Pass thru anything that is meant for fetch.
  45                break
  46                ;;
  47        esac
  48        shift
  49done
  50
  51orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
  52git-fetch --update-head-ok "$@" || exit 1
  53
  54curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
  55if test "$curr_head" != "$orig_head"
  56then
  57        # The fetch involved updating the current branch.
  58
  59        # The working tree and the index file is still based on the
  60        # $orig_head commit, but we are merging into $curr_head.
  61        # First update the working tree to match $curr_head.
  62
  63        echo >&2 "Warning: fetch updated the current branch head."
  64        echo >&2 "Warning: fast forwarding your working tree from"
  65        echo >&2 "Warning: commit $orig_head."
  66        git-update-index --refresh 2>/dev/null
  67        git-read-tree -u -m "$orig_head" "$curr_head" ||
  68                die 'Cannot fast-forward your working tree.
  69After making sure that you saved anything precious from
  70$ git diff '$orig_head'
  71output, run
  72$ git reset --hard
  73to recover.'
  74
  75fi
  76
  77merge_head=$(sed -e '/  not-for-merge   /d' \
  78        -e 's/  .*//' "$GIT_DIR"/FETCH_HEAD | \
  79        tr '\012' ' ')
  80
  81case "$merge_head" in
  82'')
  83        curr_branch=$(git-symbolic-ref HEAD | \
  84                sed -e 's|^refs/heads/||')
  85        echo >&2 "Warning: No merge candidate found because value of config option
  86         \"branch.${curr_branch}.merge\" does not match any remote branch fetched."
  87        echo >&2 "No changes."
  88        exit 0
  89        ;;
  90?*' '?*)
  91        if test -z "$orig_head"
  92        then
  93                echo >&2 "Cannot merge multiple branches into empty head"
  94                exit 1
  95        fi
  96        ;;
  97esac
  98
  99if test -z "$orig_head"
 100then
 101        git-update-ref -m "initial pull" HEAD $merge_head "" &&
 102        git-read-tree --reset -u HEAD || exit 1
 103        exit
 104fi
 105
 106merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
 107exec git-merge $no_summary $no_commit $squash $strategy_args \
 108        "$merge_name" HEAD $merge_head