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 10 11strategy_args= no_summary= no_commit= squash= 12while case"$#,$1"in0)break;; *,-*) ;; *)break;;esac 13do 14case"$1"in 15-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\ 16--no-summa|--no-summar|--no-summary) 17 no_summary=-n;; 18--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit) 19 no_commit=--no-commit;; 20--sq|--squ|--squa|--squas|--squash) 21 squash=--squash;; 22-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ 23--strateg=*|--strategy=*|\ 24-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) 25case"$#,$1"in 26*,*=*) 27 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'`;; 281,*) 29 usage ;; 30*) 31 strategy="$2" 32shift;; 33esac 34 strategy_args="${strategy_args}-s$strategy" 35;; 36-h|--h|--he|--hel|--help) 37 usage 38;; 39-*) 40# Pass thru anything that is meant for fetch. 41break 42;; 43esac 44shift 45done 46 47orig_head=$(git-rev-parse --verify HEAD)|| die "Pulling into a black hole?" 48git-fetch --update-head-ok --reflog-action=pull "$@"||exit1 49 50curr_head=$(git-rev-parse --verify HEAD) 51iftest"$curr_head"!="$orig_head" 52then 53# The fetch involved updating the current branch. 54 55# The working tree and the index file is still based on the 56# $orig_head commit, but we are merging into $curr_head. 57# First update the working tree to match $curr_head. 58 59echo>&2"Warning: fetch updated the current branch head." 60echo>&2"Warning: fast forwarding your working tree from" 61echo>&2"Warning:$orig_headcommit." 62 git-update-index --refresh2>/dev/null 63 git-read-tree -u -m"$orig_head""$curr_head"|| 64 die 'Cannot fast-forward your working tree. 65After making sure that you saved anything precious from 66$ git diff '$orig_head' 67output, run 68$ git reset --hard 69to recover.' 70 71fi 72 73merge_head=$(sed-e'/ not-for-merge /d' \ 74-e's/ .*//'"$GIT_DIR"/FETCH_HEAD | \ 75tr'\012'' ') 76 77case"$merge_head"in 78'') 79echo>&2"No changes." 80exit0 81;; 82?*' '?*) 83 var=`git-repo-config --get pull.octopus` 84iftest -n"$var" 85then 86 strategy_default_args="-s$var" 87fi 88;; 89*) 90 var=`git-repo-config --get pull.twohead` 91iftest -n"$var" 92then 93 strategy_default_args="-s$var" 94fi 95;; 96esac 97 98case"$strategy_args"in 99'') 100 strategy_args=$strategy_default_args 101;; 102esac 103 104merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")||exit 105git-merge"--reflog-action=pull $*" \ 106$no_summary $no_commit $squash $strategy_args \ 107"$merge_name" HEAD $merge_head