[PATCH] Make git-update-cache --refresh fail if update/merge needed.
[git/gitweb.git] / git-pull-script
blob4220e187321e21d18d84481c98c473fb45cca86b
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 .git/ORIG_HEAD
9 cp .git/HEAD .git/ORIG_HEAD
11 echo "Getting object database"
12 rsync -avz --ignore-existing $merge_repo/objects/. ${SHA1_FILE_DIRECTORY:-.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=$(git-merge-base $head $merge_head)
20 if [ -z "$common" ]; then
21 echo "Unable to find common commit between" $merge_head $head
22 exit 1
25 # Get the trees associated with those commits
26 common_tree=$(git-cat-file commit $common | sed 's/tree //;q')
27 head_tree=$(git-cat-file commit $head | sed 's/tree //;q')
28 merge_tree=$(git-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
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 git-read-tree -m $merge_tree && git-checkout-cache -f -a && git-update-cache --refresh
40 echo $merge_head > .git/HEAD
41 exit 0
43 echo "Trying to merge $merge_head into $head"
44 git-read-tree -m $common_tree $head_tree $merge_tree
45 merge_msg="Merge of $merge_repo"
46 result_tree=$(git-write-tree 2> /dev/null)
47 if [ $? -ne 0 ]; then
48 echo "Simple merge failed, trying Automatic merge"
49 git-merge-cache git-merge-one-file-script -a
50 merge_msg="Automatic merge of $merge_repo"
51 result_tree=$(git-write-tree) || exit 1
53 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge_head)
54 echo "Committed merge $result_commit"
55 echo $result_commit > .git/HEAD
56 git-checkout-cache -f -a && git-update-cache --refresh