git-diff-cache: add "-m" flag to match all non-checked-out files with the index.
[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
552e2bd1 7merge_name=${2:-HEAD}
839a7a06 8
9831d8f8
LT
9rm -f .git/MERGE_HEAD .git/ORIG_HEAD
10cp .git/HEAD .git/ORIG_HEAD
4aaef106 11
839a7a06 12echo "Getting object database"
d840b3b2 13rsync -avz --ignore-existing $merge_repo/objects/. ${SHA1_FILE_DIRECTORY:-.git/objects}/.
839a7a06 14
552e2bd1
LT
15echo "Getting remote $merge_name"
16rsync -L $merge_repo/$merge_name .git/MERGE_HEAD || exit 1
839a7a06
LT
17
18head=$(cat .git/HEAD)
19merge_head=$(cat .git/MERGE_HEAD)
2d280e1c 20common=$(git-merge-base $head $merge_head)
839a7a06
LT
21if [ -z "$common" ]; then
22 echo "Unable to find common commit between" $merge_head $head
23 exit 1
24fi
25
26# Get the trees associated with those commits
2d280e1c
LT
27common_tree=$(git-cat-file commit $common | sed 's/tree //;q')
28head_tree=$(git-cat-file commit $head | sed 's/tree //;q')
29merge_tree=$(git-cat-file commit $merge_head | sed 's/tree //;q')
839a7a06
LT
30
31if [ "$common" == "$merge_head" ]; then
32 echo "Already up-to-date. Yeeah!"
33 exit 0
34fi
35if [ "$common" == "$head" ]; then
36 echo "Updating from $head to $merge_head."
37 echo "Destroying all noncommitted data!"
38 echo "Kill me within 3 seconds.."
39 sleep 3
2d280e1c 40 git-read-tree -m $merge_tree && git-checkout-cache -f -a && git-update-cache --refresh
839a7a06 41 echo $merge_head > .git/HEAD
4bea3b69 42 git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1
839a7a06
LT
43 exit 0
44fi
45echo "Trying to merge $merge_head into $head"
2d280e1c 46git-read-tree -m $common_tree $head_tree $merge_tree
9831d8f8 47merge_msg="Merge of $merge_repo"
2d280e1c 48result_tree=$(git-write-tree 2> /dev/null)
9831d8f8
LT
49if [ $? -ne 0 ]; then
50 echo "Simple merge failed, trying Automatic merge"
2d280e1c 51 git-merge-cache git-merge-one-file-script -a
9831d8f8 52 merge_msg="Automatic merge of $merge_repo"
2d280e1c 53 result_tree=$(git-write-tree) || exit 1
9831d8f8 54fi
2d280e1c 55result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge_head)
839a7a06
LT
56echo "Committed merge $result_commit"
57echo $result_commit > .git/HEAD
2d280e1c 58git-checkout-cache -f -a && git-update-cache --refresh
705acc5c 59git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1