3 # git-pk3-merge: Attempt a trivial merge of master in a bare repo.
11 echo "$(basename "$0"): error: $*" >&2
21 export GIT_DIR=/path/to/xonotic-maps.pk3dir.git # absolute path
23 export GIT_AUTHOR_NAME="Some Guy"
24 export GIT_AUTHOR_EMAIL="someguy@example.com"
26 $(basename $0) nick branch
35 die "wrong number of arguments"
38 [ -z "$GIT_DIR" ] && {
44 branch=$(git check-ref-format --print "$nick/$2") ||
45 die "malformed branch name '$nick/$2'"
49 [ -z "$GIT_AUTHOR_NAME" ] && export GIT_AUTHOR_NAME="$nick"
50 [ -z "$GIT_AUTHOR_EMAIL" ] && export GIT_AUTHOR_EMAIL="${nick}@example.com"
54 echo "Merge branch 'master'"
63 [ "$cleanup_index" ] && rm -f "$GIT_INDEX_FILE"
68 # Set up index file, makes testing easier
69 [ -z "$GIT_INDEX_FILE" ] && {
70 export GIT_INDEX_FILE="$GIT_DIR/pk3-merge-index"
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"
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"
85 # Attempt a trivial merge
86 git read-tree -i -m --aggressive --trivial $base $ref $master ||
87 die "couldn't do a trivial merge"
89 # Check if the index contains changes against parent
90 git diff-index --cached --quiet $parent1 &&
91 die "found no changes to commit"
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"