]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/git-pk3-merge
rename all the configs
[xonotic/xonotic.git] / misc / tools / git-pk3-merge
1 #!/bin/sh
2
3 # git-pk3-merge: Attempt a trivial merge of master in a bare repo.
4
5 set -x
6
7 # Helpers
8
9 die()
10 {
11     echo "$(basename "$0"): error: $*" >&2
12     exit 1
13 }
14
15 usage()
16 {
17     cat <<EOF
18 Usage:
19
20   # mandatory
21   export GIT_DIR=/path/to/xonotic-maps.pk3dir.git # absolute path
22   # optional
23   export GIT_AUTHOR_NAME="Some Guy"
24   export GIT_AUTHOR_EMAIL="someguy@example.com"
25
26   $(basename $0) nick branch
27
28 EOF
29 }
30
31 # Check usage
32
33 [ $# -eq 2 ] || {
34     usage
35     die "wrong number of arguments"
36 }
37
38 [ -z "$GIT_DIR" ] && {
39     usage
40     die "GIT_DIR not set"
41 }
42
43 nick="$1"
44 branch=$(git check-ref-format --print "$nick/$2") ||
45 die "malformed branch name '$nick/$2'"
46
47 # Set up commit info
48
49 [ -z "$GIT_AUTHOR_NAME" ] && export GIT_AUTHOR_NAME="$nick"
50 [ -z "$GIT_AUTHOR_EMAIL" ] && export GIT_AUTHOR_EMAIL="${nick}@example.com"
51
52 message()
53 {
54     echo "Merge branch 'master'"
55 }
56
57 # Clean up on exit
58
59 cleanup_index=
60
61 cleanup()
62 {
63     [ "$cleanup_index" ] && rm -f "$GIT_INDEX_FILE"
64 }
65
66 trap cleanup EXIT
67
68 # Set up index file, makes testing easier
69 [ -z "$GIT_INDEX_FILE" ] && {
70     export GIT_INDEX_FILE="$GIT_DIR/pk3-merge-index"
71     cleanup_index=t
72 }
73
74 # Note the refs and the common ancestor
75 master=refs/heads/master
76 ref=refs/heads/$branch
77 base=$(git merge-base $master $ref 2> /dev/null) ||
78 die "couldn't determine the common ancestor"
79
80 # Figure out the parent commits
81 parent1=$(git rev-parse --verify -q $ref) &&
82 parent2=$(git rev-parse --verify -q $master) ||
83 die "couldn't determine parent commits"
84
85 # Attempt a trivial merge
86 git read-tree -i -m --aggressive --trivial $base $ref $master ||
87 die "couldn't do a trivial merge"
88
89 # Check if the index contains changes against parent
90 git diff-index --cached --quiet $parent1 &&
91 die "found no changes to commit"
92
93 # Commit the index and point the ref to the new commit
94 tree=$(git write-tree) &&
95 commit=$(message | git commit-tree $tree -p $parent1 -p $parent2) &&
96 git update-ref -m "pk3-merge" $ref $commit ||
97 die "couldn't commit merge"