Improve sha1 object file writing.
[git/git.git] / git-pull-script
CommitLineData
839a7a06
LT
1#!/bin/sh
2#
3# use "$1" or something in a real script, this
4# just hard-codes it.
5#
6merge_repo=$1
7
9831d8f8
LT
8rm -f .git/MERGE_HEAD .git/ORIG_HEAD
9cp .git/HEAD .git/ORIG_HEAD
4aaef106 10
839a7a06 11echo "Getting object database"
d840b3b2 12rsync -avz --ignore-existing $merge_repo/objects/. ${SHA1_FILE_DIRECTORY:-.git/objects}/.
839a7a06
LT
13
14echo "Getting remote head"
4aaef106 15rsync -L $merge_repo/HEAD .git/MERGE_HEAD || exit 1
839a7a06
LT
16
17head=$(cat .git/HEAD)
18merge_head=$(cat .git/MERGE_HEAD)
2d280e1c 19common=$(git-merge-base $head $merge_head)
839a7a06
LT
20if [ -z "$common" ]; then
21 echo "Unable to find common commit between" $merge_head $head
22 exit 1
23fi
24
25# Get the trees associated with those commits
2d280e1c
LT
26common_tree=$(git-cat-file commit $common | sed 's/tree //;q')
27head_tree=$(git-cat-file commit $head | sed 's/tree //;q')
28merge_tree=$(git-cat-file commit $merge_head | sed 's/tree //;q')
839a7a06
LT
29
30if [ "$common" == "$merge_head" ]; then
31 echo "Already up-to-date. Yeeah!"
32 exit 0
33fi
34if [ "$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
2d280e1c 39 git-read-tree -m $merge_tree && git-checkout-cache -f -a && git-update-cache --refresh
839a7a06
LT
40 echo $merge_head > .git/HEAD
41 exit 0
42fi
43echo "Trying to merge $merge_head into $head"
2d280e1c 44git-read-tree -m $common_tree $head_tree $merge_tree
9831d8f8 45merge_msg="Merge of $merge_repo"
2d280e1c 46result_tree=$(git-write-tree 2> /dev/null)
9831d8f8
LT
47if [ $? -ne 0 ]; then
48 echo "Simple merge failed, trying Automatic merge"
2d280e1c 49 git-merge-cache git-merge-one-file-script -a
9831d8f8 50 merge_msg="Automatic merge of $merge_repo"
2d280e1c 51 result_tree=$(git-write-tree) || exit 1
9831d8f8 52fi
2d280e1c 53result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge_head)
839a7a06
LT
54echo "Committed merge $result_commit"
55echo $result_commit > .git/HEAD
2d280e1c 56git-checkout-cache -f -a && git-update-cache --refresh