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