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