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