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