3 # Copyright (c) 2005 Junio C Hamano
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
7 USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
8 LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
11 strategy_args= no_summary= no_commit= squash=
12 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
15 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
16 --no-summa|--no-summar|--no-summary)
18 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
19 no_commit=--no-commit ;;
20 --sq|--squ|--squa|--squas|--squash)
22 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
23 --strateg=*|--strategy=*|\
24 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
27 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
34 strategy_args="${strategy_args}-s $strategy "
36 -h|--h|--he|--hel|--help)
40 # Pass thru anything that is meant for fetch.
47 orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
48 git-fetch --update-head-ok --reflog-action=pull "$@" || exit 1
50 curr_head=$(git-rev-parse --verify HEAD)
51 if test "$curr_head" != "$orig_head"
53 # The fetch involved updating the current branch.
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.
59 echo >&2 "Warning: fetch updated the current branch head."
60 echo >&2 "Warning: fast forwarding your working tree from"
61 echo >&2 "Warning: $orig_head commit."
62 git-update-index --refresh 2>/dev/null
63 git-read-tree -u -m "$orig_head" "$curr_head" ||
64 die 'Cannot fast-forward your working tree.
65 After making sure that you saved anything precious from
66 $ git diff '$orig_head'
73 merge_head=$(sed -e '/ not-for-merge /d' \
74 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
79 echo >&2 "No changes."
83 var=`git-repo-config --get pull.octopus`
86 strategy_default_args="-s $var"
90 var=`git-repo-config --get pull.twohead`
93 strategy_default_args="-s $var"
98 case "$strategy_args" in
100 strategy_args=$strategy_default_args
104 merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
105 git-merge $no_summary $no_commit $squash $strategy_args \
106 "$merge_name" HEAD $merge_head