git-pull.shon commit GIT 0.99.9l aka 1.0rc4 (423325a)
   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
   8
   9usage () {
  10    echo >&2 "usage: $0"' [-n] [--no-commit] [--no-summary] [--help]
  11    [-s strategy]...
  12    [<fetch-options>]
  13    <repo> <head>...
  14
  15Fetch one or more remote refs and merge it/them into the current HEAD.
  16'
  17    exit 1
  18}
  19
  20strategy_args= no_summary= no_commit=
  21while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
  22do
  23        case "$1" in
  24        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
  25                --no-summa|--no-summar|--no-summary)
  26                no_summary=-n ;;
  27        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
  28                no_commit=--no-commit ;;
  29        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
  30                --strateg=*|--strategy=*|\
  31        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
  32                case "$#,$1" in
  33                *,*=*)
  34                        strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
  35                1,*)
  36                        usage ;;
  37                *)
  38                        strategy="$2"
  39                        shift ;;
  40                esac
  41                strategy_args="${strategy_args}-s $strategy "
  42                ;;
  43        -h|--h|--he|--hel|--help)
  44                usage
  45                ;;
  46        -*)
  47                # Pass thru anything that is meant for fetch.
  48                break
  49                ;;
  50        esac
  51        shift
  52done
  53
  54orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
  55git-fetch --update-head-ok "$@" || exit 1
  56
  57curr_head=$(git-rev-parse --verify HEAD)
  58if test "$curr_head" != "$orig_head"
  59then
  60        # The fetch involved updating the current branch.
  61
  62        # The working tree and the index file is still based on the
  63        # $orig_head commit, but we are merging into $curr_head.
  64        # First update the working tree to match $curr_head.
  65
  66        echo >&2 "Warning: fetch updated the current branch head."
  67        echo >&2 "Warning: fast forwarding your working tree."
  68        git-read-tree -u -m "$orig_head" "$curr_head" ||
  69                die "You need to first update your working tree."
  70fi
  71
  72merge_head=$(sed -e '/  not-for-merge   /d' \
  73        -e 's/  .*//' "$GIT_DIR"/FETCH_HEAD | \
  74        tr '\012' ' ')
  75
  76case "$merge_head" in
  77'')
  78        echo >&2 "No changes."
  79        exit 0
  80        ;;
  81?*' '?*)
  82        var=`git-var -l | sed -ne 's/^pull\.octopus=/-s /p'`
  83        if test '' = "$var"
  84        then
  85                strategy_default_args='-s octopus'
  86        else
  87                strategy_default_args=$var
  88        fi
  89        ;;
  90*)
  91        var=`git-var -l | sed -ne 's/^pull\.twohead=/-s /p'`
  92        if test '' = "$var"
  93        then
  94                strategy_default_args='-s recursive'
  95        else
  96                strategy_default_args=$var
  97        fi
  98        ;;
  99esac
 100
 101case "$strategy_args" in
 102'')
 103        strategy_args=$strategy_default_args
 104        ;;
 105esac
 106
 107merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
 108git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head