Code

Allow writing to the private index file mapping.
[git.git] / git-pull-script
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 .git/ORIG_HEAD
9 cp .git/HEAD .git/ORIG_HEAD
11 echo "Getting object database"
12 rsync -avz --ignore-existing $merge_repo/objects/. .git/objects/.
14 echo "Getting remote head"
15 rsync -L $merge_repo/HEAD .git/MERGE_HEAD || exit 1
17 head=$(cat .git/HEAD)
18 merge_head=$(cat .git/MERGE_HEAD)
19 common=$(merge-base $head $merge_head)
20 if [ -z "$common" ]; then
21         echo "Unable to find common commit between" $merge_head $head
22         exit 1
23 fi
25 # Get the trees associated with those commits
26 common_tree=$(cat-file commit $common | sed 's/tree //;q')
27 head_tree=$(cat-file commit $head | sed 's/tree //;q')
28 merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')
30 if [ "$common" == "$merge_head" ]; then
31         echo "Already up-to-date. Yeeah!"
32         exit 0
33 fi
34 if [ "$common" == "$head" ]; then
35         echo "Updating from $head to $merge_head."
36         echo "Destroying all noncommitted data!"
37         echo "Kill me within 3 seconds.."
38         sleep 3
39         read-tree -m $merge_tree && checkout-cache -f -a && update-cache --refresh
40         echo $merge_head > .git/HEAD
41         exit 0
42 fi
43 echo "Trying to merge $merge_head into $head"
44 read-tree -m $common_tree $head_tree $merge_tree
45 merge_msg="Merge of $merge_repo"
46 result_tree=$(write-tree  2> /dev/null)
47 if [ $? -ne 0 ]; then
48         echo "Simple merge failed, trying Automatic merge"
49         merge-cache git-merge-one-file-script -a
50         merge_msg="Automatic merge of $merge_repo"
51         result_tree=$(write-tree) || exit 1
52 fi
53 result_commit=$(echo "$merge_msg" | commit-tree $result_tree -p $head -p $merge_head)
54 echo "Committed merge $result_commit"
55 echo $result_commit > .git/HEAD
56 checkout-cache -f -a && update-cache --refresh