]> git.ipfire.org Git - thirdparty/git.git/blame - git-pull.sh
Make git-blame fail when working tree is needed and we're not in one
[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
5072a323 7USAGE='[-n | --no-summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...'
806f36d4 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
5072a323 18strategy_args= no_summary= no_commit= squash= no_ff=
822f7c73 19while :
60fb5b2c
JH
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 ;;
51e7ecf4
AR
25 --summary)
26 no_summary=$1
27 ;;
123ee3ca
JH
28 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
29 no_commit=--no-commit ;;
5072a323
LH
30 --c|--co|--com|--comm|--commi|--commit)
31 no_commit=--commit ;;
7d0c6887
JH
32 --sq|--squ|--squa|--squas|--squash)
33 squash=--squash ;;
5072a323
LH
34 --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
35 squash=--no-squash ;;
36 --ff)
37 no_ff=--ff ;;
38 --no-ff)
39 no_ff=--no-ff ;;
60fb5b2c
JH
40 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
41 --strateg=*|--strategy=*|\
42 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
43 case "$#,$1" in
44 *,*=*)
8096fae7 45 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
60fb5b2c
JH
46 1,*)
47 usage ;;
48 *)
49 strategy="$2"
50 shift ;;
51 esac
52 strategy_args="${strategy_args}-s $strategy "
53 ;;
93d69d86
JL
54 -h|--h|--he|--hel|--help)
55 usage
56 ;;
822f7c73
DK
57 *)
58 # Pass thru anything that may be meant for fetch.
619e5a0e 59 break
60fb5b2c
JH
60 ;;
61 esac
62 shift
63done
64
5be60078 65orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
f9474132 66git-fetch --update-head-ok "$@" || exit 1
b10ac50f 67
5be60078 68curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
b10ac50f
JH
69if test "$curr_head" != "$orig_head"
70then
71 # The fetch involved updating the current branch.
72
73 # The working tree and the index file is still based on the
74 # $orig_head commit, but we are merging into $curr_head.
75 # First update the working tree to match $curr_head.
76
77 echo >&2 "Warning: fetch updated the current branch head."
cf46e7b8 78 echo >&2 "Warning: fast forwarding your working tree from"
a057f806 79 echo >&2 "Warning: commit $orig_head."
5be60078
JH
80 git update-index --refresh 2>/dev/null
81 git read-tree -u -m "$orig_head" "$curr_head" ||
8323124a
JH
82 die 'Cannot fast-forward your working tree.
83After making sure that you saved anything precious from
84$ git diff '$orig_head'
85output, run
86$ git reset --hard
87to recover.'
88
b10ac50f
JH
89fi
90
05dd8e2e
JH
91merge_head=$(sed -e '/ not-for-merge /d' \
92 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
93 tr '\012' ' ')
e0bfc81e
JH
94
95case "$merge_head" in
521003ff 96'')
5be60078 97 curr_branch=$(git symbolic-ref -q HEAD)
a74b1706
JK
98 case $? in
99 0) ;;
100 1) echo >&2 "You are not currently on a branch; you must explicitly"
101 echo >&2 "specify which branch you wish to merge:"
102 echo >&2 " git pull <remote> <branch>"
103 exit 1;;
104 *) exit $?;;
105 esac
106 curr_branch=${curr_branch#refs/heads/}
107
8fc293cb
FMQ
108 echo >&2 "You asked me to pull without telling me which branch you"
109 echo >&2 "want to merge with, and 'branch.${curr_branch}.merge' in"
110 echo >&2 "your configuration file does not tell me either. Please"
111 echo >&2 "name which branch you want to merge on the command line and"
112 echo >&2 "try again (e.g. 'git pull <repository> <refspec>')."
113 echo >&2 "See git-pull(1) for details on the refspec."
114 echo >&2
115 echo >&2 "If you often merge with the same branch, you may want to"
116 echo >&2 "configure the following variables in your configuration"
117 echo >&2 "file:"
118 echo >&2
119 echo >&2 " branch.${curr_branch}.remote = <nickname>"
120 echo >&2 " branch.${curr_branch}.merge = <remote-ref>"
121 echo >&2 " remote.<nickname>.url = <url>"
122 echo >&2 " remote.<nickname>.fetch = <refspec>"
123 echo >&2
124 echo >&2 "See git-config(1) for details."
125 exit 1
521003ff 126 ;;
60fb5b2c 127?*' '?*)
d09e79cb
LT
128 if test -z "$orig_head"
129 then
130 echo >&2 "Cannot merge multiple branches into empty head"
131 exit 1
132 fi
60fb5b2c
JH
133 ;;
134esac
135
d09e79cb
LT
136if test -z "$orig_head"
137then
5be60078
JH
138 git update-ref -m "initial pull" HEAD $merge_head "" &&
139 git read-tree --reset -u HEAD || exit 1
d09e79cb
LT
140 exit
141fi
142
5be60078 143merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
5072a323 144exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \
7d0c6887 145 "$merge_name" HEAD $merge_head