1 #!/bin/sh
2 #
3 # use "$1" or something in a real script, this
4 # just hard-codes it.
5 #
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
22 fi
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
32 fi
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
41 fi
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