git-hacks

git-hacks Commit Details

Date:2014-02-01 16:56:22 (4 years 8 months ago)
Author:Nicola Fontana
Branch:master
Commit:ddee25a8d573e6a13830970bbf02a5e9a0988912
Parents: 6f967017aa126c83914f88b5d2585da2a23a8976
Message:post-receive.automerge: initial import

Changes:
Apost-receive.automerge (full)

File differences

post-receive.automerge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /bin/sh
#
# This is intended to be run inside a non-bare repository. It will
# merge the local working tree with the latest pushed changes after
# every git push, # automatically resolving conflicts by creating a
# copy of each conflicting file.
#
# I am using it for two-way file synchronization between different
# git repositories: on this side I have this hook enabled and on the
# other side (possibly more than one) I have to do the following in
# order to synchronize the repositories:
#
# ----->8------
# #! /bin/sh
# # Synchronize this repository with the default remote
#
# git add --all
# git commit --allow-empty -m Autocommit
# git push
# git pull
# -----8<------
#
# Copyright (c) 2014 Nicola Fontana <ntd at entidi.it>
#
# This file is licensed under the GPL v2, or a later version
# at the discretion of Nicola Fontana or any other official
# post-receive.automerge maintainer.
message='Commit from post-receive.automerge'
unset GIT_DIR
cd ..
# Generate the local tree object to be merged with HEAD
GIT_INDEX_FILE=.git/tmpindex git add --all
tree=`GIT_INDEX_FILE=.git/tmpindex git write-tree`
# Reset to the latest push state
rm -f .git/tmpindex
git reset -q --hard
git clean -qfxd
# Check if there is something to merge in the tree
[ -z "$tree" ] && exit 0
commit=`git commit-tree -p HEAD^ -m "$message" $tree`
[ -z "$commit" ] && exit 0
# Commit local changes
git cherry-pick -rn $commit
topdir=`git rev-parse --show-toplevel`
for f in `git diff --name-only --diff-filter=U`; do
f2=`mktemp -p "$topdir" "$f-conflict-XXXX"`
git checkout --theirs "$f"
mv "$f" "$f2"
git checkout --ours "$f"
git add "$f" "$f2"
done
git commit -m "$message"

Archive Download the corresponding diff file

Branches