git-pull.shon commit [PATCH] Enable and fix support for base less merges. (88f8f0a)
   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
   7. git-sh-setup || die "Not a git archive"
   8
   9usage () {
  10    die "git pull [-n] [-s strategy]... <repo> <head>..."
  11}
  12
  13strategy_args= no_summary=
  14while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
  15do
  16        case "$1" in
  17        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
  18                --no-summa|--no-summar|--no-summary)
  19                no_summary=-n ;;
  20        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
  21                --strateg=*|--strategy=*|\
  22        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
  23                case "$#,$1" in
  24                *,*=*)
  25                        strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
  26                1,*)
  27                        usage ;;
  28                *)
  29                        strategy="$2"
  30                        shift ;;
  31                esac
  32                strategy_args="${strategy_args}-s $strategy "
  33                ;;
  34        -*)
  35                usage
  36                ;;
  37        esac
  38        shift
  39done
  40
  41orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
  42git-fetch --update-head-ok "$@" || exit 1
  43
  44curr_head=$(git-rev-parse --verify HEAD)
  45if test "$curr_head" != "$orig_head"
  46then
  47        # The fetch involved updating the current branch.
  48
  49        # The working tree and the index file is still based on the
  50        # $orig_head commit, but we are merging into $curr_head.
  51        # First update the working tree to match $curr_head.
  52
  53        echo >&2 "Warning: fetch updated the current branch head."
  54        echo >&2 "Warning: fast forwarding your working tree."
  55        git-read-tree -u -m "$orig_head" "$curr_head" ||
  56                die "You need to first update your working tree."
  57fi
  58
  59merge_head=$(sed -e '/  not-for-merge   /d' \
  60        -e 's/  .*//' "$GIT_DIR"/FETCH_HEAD | \
  61        tr '\012' ' ')
  62
  63case "$merge_head" in
  64'')
  65        echo >&2 "No changes."
  66        exit 0
  67        ;;
  68?*' '?*)
  69        strategy_default_args='-s octopus'
  70        ;;
  71*)
  72        strategy_default_args='-s resolve'
  73        ;;
  74esac
  75
  76case "$strategy_args" in
  77'')
  78        strategy_args=$strategy_default_args
  79        ;;
  80esac
  81
  82merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
  83git-merge $no_summary $strategy_args "$merge_name" HEAD $merge_head