Teach "git-pull-script" about alternate HEAD's to pull..
[git/spearce.git] / git-pull-script
blobe7e82f49d2a243060dfc653dad200675f8336688
1 #!/bin/sh
3 # use "$1" or something in a real script, this
4 # just hard-codes it.
6 merge_repo=$1
7 merge_name=${2:-HEAD}
9 rm -f .git/MERGE_HEAD .git/ORIG_HEAD
10 cp .git/HEAD .git/ORIG_HEAD
12 echo "Getting object database"
13 rsync -avz --ignore-existing $merge_repo/objects/. ${SHA1_FILE_DIRECTORY:-.git/objects}/.
15 echo "Getting remote $merge_name"
16 rsync -L $merge_repo/$merge_name .git/MERGE_HEAD || exit 1
18 head=$(cat .git/HEAD)
19 merge_head=$(cat .git/MERGE_HEAD)
20 common=$(git-merge-base $head $merge_head)
21 if [ -z "$common" ]; then
22 echo "Unable to find common commit between" $merge_head $head
23 exit 1
26 # Get the trees associated with those commits
27 common_tree=$(git-cat-file commit $common | sed 's/tree //;q')
28 head_tree=$(git-cat-file commit $head | sed 's/tree //;q')
29 merge_tree=$(git-cat-file commit $merge_head | sed 's/tree //;q')
31 if [ "$common" == "$merge_head" ]; then
32 echo "Already up-to-date. Yeeah!"
33 exit 0
35 if [ "$common" == "$head" ]; then
36 echo "Updating from $head to $merge_head."
37 echo "Destroying all noncommitted data!"
38 echo "Kill me within 3 seconds.."
39 sleep 3
40 git-read-tree -m $merge_tree && git-checkout-cache -f -a && git-update-cache --refresh
41 echo $merge_head > .git/HEAD
42 exit 0
44 echo "Trying to merge $merge_head into $head"
45 git-read-tree -m $common_tree $head_tree $merge_tree
46 merge_msg="Merge of $merge_repo"
47 result_tree=$(git-write-tree 2> /dev/null)
48 if [ $? -ne 0 ]; then
49 echo "Simple merge failed, trying Automatic merge"
50 git-merge-cache git-merge-one-file-script -a
51 merge_msg="Automatic merge of $merge_repo"
52 result_tree=$(git-write-tree) || exit 1
54 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge_head)
55 echo "Committed merge $result_commit"
56 echo $result_commit > .git/HEAD
57 git-checkout-cache -f -a && git-update-cache --refresh
58 git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1