GIT 0.99.9d
[git] / git-pull.sh
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
7 . git-sh-setup || die "Not a git archive"
8
9 usage () {
10     die "git pull [-n] [--no-commit] [-s strategy]... <repo> <head>..."
11 }
12
13 strategy_args= no_summary= no_commit=
14 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
15 do
16         case "$1" in
17         -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
18                 --no-summa|--no-summar|--no-summary)
19                 no_summary=-n ;;
20         --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
21                 no_commit=--no-commit ;;
22         -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
23                 --strateg=*|--strategy=*|\
24         -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
25                 case "$#,$1" in
26                 *,*=*)
27                         strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
28                 1,*)
29                         usage ;;
30                 *)
31                         strategy="$2"
32                         shift ;;
33                 esac
34                 strategy_args="${strategy_args}-s $strategy "
35                 ;;
36         -*)
37                 # Pass thru anything that is meant for fetch.
38                 break
39                 ;;
40         esac
41         shift
42 done
43
44 orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
45 git-fetch --update-head-ok "$@" || exit 1
46
47 curr_head=$(git-rev-parse --verify HEAD)
48 if test "$curr_head" != "$orig_head"
49 then
50         # The fetch involved updating the current branch.
51
52         # The working tree and the index file is still based on the
53         # $orig_head commit, but we are merging into $curr_head.
54         # First update the working tree to match $curr_head.
55
56         echo >&2 "Warning: fetch updated the current branch head."
57         echo >&2 "Warning: fast forwarding your working tree."
58         git-read-tree -u -m "$orig_head" "$curr_head" ||
59                 die "You need to first update your working tree."
60 fi
61
62 merge_head=$(sed -e '/  not-for-merge   /d' \
63         -e 's/  .*//' "$GIT_DIR"/FETCH_HEAD | \
64         tr '\012' ' ')
65
66 case "$merge_head" in
67 '')
68         echo >&2 "No changes."
69         exit 0
70         ;;
71 ?*' '?*)
72         strategy_default_args='-s octopus'
73         ;;
74 *)
75         strategy_default_args='-s resolve'
76         ;;
77 esac
78
79 case "$strategy_args" in
80 '')
81         strategy_args=$strategy_default_args
82         ;;
83 esac
84
85 merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
86 git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head