blob: 4611ae644e08e4ab115633ab86f1f02976663169 [file] [log] [blame]
Linus Torvalds839a7a02005-04-18 12:15:10 -07001#!/bin/sh
2#
Junio C Hamano521003f2005-08-22 21:57:59 -07003# Copyright (c) 2005 Junio C Hamano
4#
5# Fetch one or more remote refs and merge it/them into the current HEAD.
6
freku045@student.liu.se806f36d2005-12-13 23:30:31 +01007USAGE='[-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.'
Junio C Hamanoae2b0f12005-11-24 00:12:11 -08009. git-sh-setup
Junio C Hamanob10ac502005-08-25 18:15:32 -070010
Junio C Hamano123ee3c2005-11-01 19:30:11 -080011strategy_args= no_summary= no_commit=
Junio C Hamano60fb5b22005-09-25 19:43:51 -070012while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
13do
14 case "$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 ;;
Junio C Hamano123ee3c2005-11-01 19:30:11 -080018 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
19 no_commit=--no-commit ;;
Junio C Hamano60fb5b22005-09-25 19:43:51 -070020 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
21 --strateg=*|--strategy=*|\
22 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
23 case "$#,$1" in
24 *,*=*)
25 strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
26 1,*)
27 usage ;;
28 *)
29 strategy="$2"
30 shift ;;
31 esac
32 strategy_args="${strategy_args}-s $strategy "
33 ;;
Jon Loeliger93d69d82005-11-06 23:30:56 -060034 -h|--h|--he|--hel|--help)
35 usage
36 ;;
Junio C Hamano60fb5b22005-09-25 19:43:51 -070037 -*)
Junio C Hamano619e5a02005-10-03 15:45:44 -070038 # Pass thru anything that is meant for fetch.
39 break
Junio C Hamano60fb5b22005-09-25 19:43:51 -070040 ;;
41 esac
42 shift
43done
44
Junio C Hamanobf7960e2005-09-27 18:14:27 -070045orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
Junio C Hamano215a7ad2005-09-07 17:26:23 -070046git-fetch --update-head-ok "$@" || exit 1
Junio C Hamanob10ac502005-08-25 18:15:32 -070047
Junio C Hamanobf7960e2005-09-27 18:14:27 -070048curr_head=$(git-rev-parse --verify HEAD)
Junio C Hamanob10ac502005-08-25 18:15:32 -070049if test "$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
57 echo >&2 "Warning: fetch updated the current branch head."
Junio C Hamanocf46e7b2006-03-22 01:09:43 -080058 echo >&2 "Warning: fast forwarding your working tree from"
59 echo >&2 "Warning: $orig_head commit."
60 git-update-index --refresh 2>/dev/null
Junio C Hamanob10ac502005-08-25 18:15:32 -070061 git-read-tree -u -m "$orig_head" "$curr_head" ||
Junio C Hamano83231242006-03-22 01:57:11 -080062 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
Junio C Hamanob10ac502005-08-25 18:15:32 -070069fi
70
Junio C Hamano05dd8e22005-09-25 22:54:23 -070071merge_head=$(sed -e '/ not-for-merge /d' \
72 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
73 tr '\012' ' ')
Junio C Hamanoe0bfc812005-08-20 02:57:26 -070074
75case "$merge_head" in
Junio C Hamano521003f2005-08-22 21:57:59 -070076'')
77 echo >&2 "No changes."
78 exit 0
79 ;;
Junio C Hamano60fb5b22005-09-25 19:43:51 -070080?*' '?*)
Junio C Hamanof5ef5352006-03-18 02:07:59 -080081 var=`git-repo-config --get pull.octopus`
Mark Hollomonc8e2db02006-03-15 22:51:41 +000082 if test -n "$var"
Junio C Hamanoa1c29292005-11-08 02:00:31 -080083 then
Junio C Hamano4890f622006-02-11 12:39:11 -080084 strategy_default_args="-s $var"
Junio C Hamanoa1c29292005-11-08 02:00:31 -080085 fi
Junio C Hamano60fb5b22005-09-25 19:43:51 -070086 ;;
87*)
Junio C Hamanof5ef5352006-03-18 02:07:59 -080088 var=`git-repo-config --get pull.twohead`
Mark Hollomonc8e2db02006-03-15 22:51:41 +000089 if test -n "$var"
90 then
Junio C Hamano4890f622006-02-11 12:39:11 -080091 strategy_default_args="-s $var"
Junio C Hamanoa1c29292005-11-08 02:00:31 -080092 fi
Junio C Hamano60fb5b22005-09-25 19:43:51 -070093 ;;
94esac
95
96case "$strategy_args" in
97'')
98 strategy_args=$strategy_default_args
Junio C Hamanoacfadcf2005-09-21 14:01:56 -070099 ;;
Junio C Hamanoe0bfc812005-08-20 02:57:26 -0700100esac
101
Junio C Hamanoc8b48ba2005-09-22 00:55:22 -0700102merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
Junio C Hamano123ee3c2005-11-01 19:30:11 -0800103git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head