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