From 508096a6856476daabb76212f67e2e723132b488 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C4=81nis=20R=C5=ABcis?= Date: Mon, 16 Aug 2010 13:02:02 +0300 Subject: [PATCH] Add a script for importing a PK3 into a bare repo --- misc/tools/git-import-pk3 | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 misc/tools/git-import-pk3 diff --git a/misc/tools/git-import-pk3 b/misc/tools/git-import-pk3 new file mode 100755 index 00000000..54c8593e --- /dev/null +++ b/misc/tools/git-import-pk3 @@ -0,0 +1,107 @@ +#!/bin/sh + +# git-import-pk3: Import a PK3 into a branch of a bare Git repo. + +set -x + +# Helpers + +die() +{ + echo "$(basename "$0"): error: $*" >&2 + exit 1 +} + +usage() +{ + cat < /dev/null +} + +# Extract the PK3 (the -n suppresses prompting in an edge case) +# FIXME: perhaps the caller should handle extraction and clean up +unzip -n -qq "$pk3path" -d "$GIT_WORK_TREE" || +die "couldn't extract PK3 contents" +trap 'find "$GIT_WORK_TREE" -mindepth 1 -delete' EXIT + +# Note the refs +master=refs/heads/master +ref=refs/heads/$branch + +# Figure out the parent commit +parent=\ +$(git rev-parse --verify -q $ref || git rev-parse --verify -q $master) || +die "couldn't determine parent commit" + +# Read the tree at master into index +git read-tree $master || +die "couldn't initialize index" + +# Reject any modified files, the mapper should create a branch instead +[ -z "$(git diff-files --diff-filter=M)" ] || +die "found changes to files in master" + +# Add untracked files; to filter out generated files such as BSP, add +# them to .gitignore and push, --exclude-standard should take care of +# the rest +git ls-files --exclude-standard -o -z | +git update-index --add -z --stdin || +die "couldn't add files to index" + +# Check if the index contains changes against parent +git diff-index --cached --quiet $parent && +die "found no changes to commit" + +# Commit the index and point the ref to the new commit +tree=$(git write-tree) && +commit=$(message | git commit-tree $tree -p $parent) && +git update-ref -m "import-pk3: $pk3name" $ref $commit || +die "couldn't commit changes" -- 2.39.2