Verify remote packs, speed up pending request queue
[git/dscho.git] / git-pull.sh
blobe23d4f559790fed079bb5759fd5aa11a8804f191
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
7 . git-sh-setup || die "Not a git archive"
9 usage () {
10 die "git pull [-n] [--no-commit] [-s strategy]... <repo> <head>..."
13 strategy_args= no_summary= no_commit=
14 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
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 ;;
31 strategy="$2"
32 shift ;;
33 esac
34 strategy_args="${strategy_args}-s $strategy "
36 -*)
37 # Pass thru anything that is meant for fetch.
38 break
40 esac
41 shift
42 done
44 orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
45 git-fetch --update-head-ok "$@" || exit 1
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.
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.
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."
62 merge_head=$(sed -e '/ not-for-merge /d' \
63 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
64 tr '\012' ' ')
66 case "$merge_head" in
67 '')
68 echo >&2 "No changes."
69 exit 0
71 ?*' '?*)
72 strategy_default_args='-s octopus'
75 strategy_default_args='-s resolve'
77 esac
79 case "$strategy_args" in
80 '')
81 strategy_args=$strategy_default_args
83 esac
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