Don't parse commit objects more than once.
[git/spearce.git] / git-pull-script
blobb873203ccc70292c08aa0c996ec02b757a93c3ef
1 #!/bin/sh
3 # use "$1" or something in a real script, this
4 # just hard-codes it.
6 merge_repo=$1
8 echo "Getting object database"
9 rsync -avz --ignore-existing $merge_repo/objects/. .git/objects/.
11 echo "Getting remote head"
12 rsync -avz $merge_repo/HEAD .git/MERGE_HEAD
14 head=$(cat .git/HEAD)
15 merge_head=$(cat .git/MERGE_HEAD)
16 common=$(merge-base $head $merge_head)
17 if [ -z "$common" ]; then
18 echo "Unable to find common commit between" $merge_head $head
19 exit 1
22 # Get the trees associated with those commits
23 common_tree=$(cat-file commit $common | sed 's/tree //;q')
24 head_tree=$(cat-file commit $head | sed 's/tree //;q')
25 merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')
27 if [ "$common" == "$merge_head" ]; then
28 echo "Already up-to-date. Yeeah!"
29 exit 0
31 if [ "$common" == "$head" ]; then
32 echo "Updating from $head to $merge_head."
33 echo "Destroying all noncommitted data!"
34 echo "Kill me within 3 seconds.."
35 sleep 3
36 read-tree $merge_tree && checkout-cache -f -a && update-cache --refresh
37 echo $merge_head > .git/HEAD
38 exit 0
40 echo "Trying to merge $merge_head into $head"
41 read-tree -m $common_tree $head_tree $merge_tree
42 result_tree=$(write-tree) || exit 1
43 result_commit=$(echo "Merge $merge_repo" | commit-tree $result_tree -p $head -p $merge_head)
44 echo "Committed merge $result_commit"
45 echo $result_commit > .git/HEAD
46 read-tree $result_tree && checkout-cache -f -a && update-cache --refresh