git-pull.shon commit Add support for pushing to a remote repository using HTTP/DAV (58e60dd)
   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] [--no-commit] [-s strategy]... <repo> <head>..."
  11}
  12
  13strategy_args= no_summary= no_commit=
  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        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
  21                no_commit=--no-commit ;;
  22        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
  23                --strateg=*|--strategy=*|\
  24        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
  25                case "$#,$1" in
  26                *,*=*)
  27                        strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
  28                1,*)
  29                        usage ;;
  30                *)
  31                        strategy="$2"
  32                        shift ;;
  33                esac
  34                strategy_args="${strategy_args}-s $strategy "
  35                ;;
  36        -*)
  37                # Pass thru anything that is meant for fetch.
  38                break
  39                ;;
  40        esac
  41        shift
  42done
  43
  44orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
  45git-fetch --update-head-ok "$@" || exit 1
  46
  47curr_head=$(git-rev-parse --verify HEAD)
  48if test "$curr_head" != "$orig_head"
  49then
  50        # The fetch involved updating the current branch.
  51
  52        # The working tree and the index file is still based on the
  53        # $orig_head commit, but we are merging into $curr_head.
  54        # First update the working tree to match $curr_head.
  55
  56        echo >&2 "Warning: fetch updated the current branch head."
  57        echo >&2 "Warning: fast forwarding your working tree."
  58        git-read-tree -u -m "$orig_head" "$curr_head" ||
  59                die "You need to first update your working tree."
  60fi
  61
  62merge_head=$(sed -e '/  not-for-merge   /d' \
  63        -e 's/  .*//' "$GIT_DIR"/FETCH_HEAD | \
  64        tr '\012' ' ')
  65
  66case "$merge_head" in
  67'')
  68        echo >&2 "No changes."
  69        exit 0
  70        ;;
  71?*' '?*)
  72        strategy_default_args='-s octopus'
  73        ;;
  74*)
  75        strategy_default_args='-s resolve'
  76        ;;
  77esac
  78
  79case "$strategy_args" in
  80'')
  81        strategy_args=$strategy_default_args
  82        ;;
  83esac
  84
  85merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
  86git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head