]> git.ipfire.org Git - thirdparty/git.git/blame - git-pull.sh
Some more memory leak avoidance
[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.'
ae2b0f15 9. git-sh-setup
b10ac50f 10
123ee3ca 11strategy_args= no_summary= no_commit=
60fb5b2c
JH
12while 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 ;;
123ee3ca
JH
18 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
19 no_commit=--no-commit ;;
60fb5b2c
JH
20 -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 ;;
93d69d86
JL
34 -h|--h|--he|--hel|--help)
35 usage
36 ;;
60fb5b2c 37 -*)
619e5a0e
JH
38 # Pass thru anything that is meant for fetch.
39 break
60fb5b2c
JH
40 ;;
41 esac
42 shift
43done
44
bf7960eb 45orig_head=$(git-rev-parse --verify HEAD) || die "Pulling into a black hole?"
215a7ad1 46git-fetch --update-head-ok "$@" || exit 1
b10ac50f 47
bf7960eb 48curr_head=$(git-rev-parse --verify HEAD)
b10ac50f
JH
49if 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."
cf46e7b8
JH
58 echo >&2 "Warning: fast forwarding your working tree from"
59 echo >&2 "Warning: $orig_head commit."
60 git-update-index --refresh 2>/dev/null
b10ac50f 61 git-read-tree -u -m "$orig_head" "$curr_head" ||
8323124a
JH
62 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
b10ac50f
JH
69fi
70
05dd8e2e
JH
71merge_head=$(sed -e '/ not-for-merge /d' \
72 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
73 tr '\012' ' ')
e0bfc81e
JH
74
75case "$merge_head" in
521003ff
JH
76'')
77 echo >&2 "No changes."
78 exit 0
79 ;;
60fb5b2c 80?*' '?*)
f5ef535f 81 var=`git-repo-config --get pull.octopus`
c8e2db00 82 if test -n "$var"
a1c29295 83 then
4890f62b 84 strategy_default_args="-s $var"
a1c29295 85 fi
60fb5b2c
JH
86 ;;
87*)
f5ef535f 88 var=`git-repo-config --get pull.twohead`
c8e2db00
MH
89 if test -n "$var"
90 then
4890f62b 91 strategy_default_args="-s $var"
a1c29295 92 fi
60fb5b2c
JH
93 ;;
94esac
95
96case "$strategy_args" in
97'')
98 strategy_args=$strategy_default_args
acfadcfb 99 ;;
e0bfc81e
JH
100esac
101
c8b48ba4 102merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
123ee3ca 103git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head