]> git.ipfire.org Git - thirdparty/git.git/blame - git-pull.sh
Fix an "implicit function definition" warning.
[thirdparty/git.git] / git-pull.sh
CommitLineData
839a7a06
LT
1#!/bin/sh
2#
521003ff
JH
3# Copyright (c) 2005 Junio C Hamano
4#
5# Fetch one or more remote refs and merge it/them into the current HEAD.
6
806f36d4
FK
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.'
533b7039 9SUBDIRECTORY_OK=Yes
ae2b0f15 10. git-sh-setup
f9474132 11set_reflog_action "pull $*"
7eff28a9 12require_work_tree
533b7039 13cd_to_toplevel
b10ac50f 14
d1014a17 15test -z "$(git ls-files -u)" ||
533b7039 16 die "You are in the middle of a conflicted merge."
d1014a17 17
7d0c6887 18strategy_args= no_summary= no_commit= squash=
60fb5b2c
JH
19while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
20do
21 case "$1" in
22 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
23 --no-summa|--no-summar|--no-summary)
24 no_summary=-n ;;
123ee3ca
JH
25 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
26 no_commit=--no-commit ;;
7d0c6887
JH
27 --sq|--squ|--squa|--squas|--squash)
28 squash=--squash ;;
60fb5b2c
JH
29 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
30 --strateg=*|--strategy=*|\
31 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
32 case "$#,$1" in
33 *,*=*)
8096fae7 34 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
60fb5b2c
JH
35 1,*)
36 usage ;;
37 *)
38 strategy="$2"
39 shift ;;
40 esac
41 strategy_args="${strategy_args}-s $strategy "
42 ;;
93d69d86
JL
43 -h|--h|--he|--hel|--help)
44 usage
45 ;;
60fb5b2c 46 -*)
619e5a0e
JH
47 # Pass thru anything that is meant for fetch.
48 break
60fb5b2c
JH
49 ;;
50 esac
51 shift
52done
53
d09e79cb 54orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
f9474132 55git-fetch --update-head-ok "$@" || exit 1
b10ac50f 56
d09e79cb 57curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
b10ac50f
JH
58if test "$curr_head" != "$orig_head"
59then
60 # The fetch involved updating the current branch.
61
62 # The working tree and the index file is still based on the
63 # $orig_head commit, but we are merging into $curr_head.
64 # First update the working tree to match $curr_head.
65
66 echo >&2 "Warning: fetch updated the current branch head."
cf46e7b8 67 echo >&2 "Warning: fast forwarding your working tree from"
a057f806 68 echo >&2 "Warning: commit $orig_head."
cf46e7b8 69 git-update-index --refresh 2>/dev/null
b10ac50f 70 git-read-tree -u -m "$orig_head" "$curr_head" ||
8323124a
JH
71 die 'Cannot fast-forward your working tree.
72After making sure that you saved anything precious from
73$ git diff '$orig_head'
74output, run
75$ git reset --hard
76to recover.'
77
b10ac50f
JH
78fi
79
05dd8e2e
JH
80merge_head=$(sed -e '/ not-for-merge /d' \
81 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
82 tr '\012' ' ')
e0bfc81e
JH
83
84case "$merge_head" in
521003ff 85'')
a74b1706
JK
86 curr_branch=$(git-symbolic-ref -q HEAD)
87 case $? in
88 0) ;;
89 1) echo >&2 "You are not currently on a branch; you must explicitly"
90 echo >&2 "specify which branch you wish to merge:"
91 echo >&2 " git pull <remote> <branch>"
92 exit 1;;
93 *) exit $?;;
94 esac
95 curr_branch=${curr_branch#refs/heads/}
96
4363dfbe
JW
97 echo >&2 "Warning: No merge candidate found because value of config option
98 \"branch.${curr_branch}.merge\" does not match any remote branch fetched."
521003ff
JH
99 echo >&2 "No changes."
100 exit 0
101 ;;
60fb5b2c 102?*' '?*)
d09e79cb
LT
103 if test -z "$orig_head"
104 then
105 echo >&2 "Cannot merge multiple branches into empty head"
106 exit 1
107 fi
60fb5b2c
JH
108 ;;
109esac
110
d09e79cb
LT
111if test -z "$orig_head"
112then
113 git-update-ref -m "initial pull" HEAD $merge_head "" &&
114 git-read-tree --reset -u HEAD || exit 1
115 exit
116fi
117
86378b32 118merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
bf699582 119exec git-merge $no_summary $no_commit $squash $strategy_args \
7d0c6887 120 "$merge_name" HEAD $merge_head