From: Jānis Rūcis Date: Mon, 16 Aug 2010 17:01:50 +0000 (+0300) Subject: s/import-pk3/pk3-import/ X-Git-Tag: xonotic-v0.1.0preview~292^2~1 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fxonotic.git;a=commitdiff_plain;h=4de26d55ac4c258d96b69c2f05bef57eb3b046ee s/import-pk3/pk3-import/ --- diff --git a/misc/tools/git-import-pk3 b/misc/tools/git-import-pk3 deleted file mode 100755 index b6d04826..00000000 --- a/misc/tools/git-import-pk3 +++ /dev/null @@ -1,133 +0,0 @@ -#!/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 -} - -# Clean up on exit - -cleanup_index= -cleanup_worktree= - -cleanup() -{ - [ "$cleanup_index" ] && rm -f "$GIT_INDEX_FILE" - [ "$cleanup_worktree" ] && find "$GIT_WORK_TREE" -mindepth 1 -delete -} - -trap cleanup EXIT - -# Set up index file, makes testing easier -[ -z "$GIT_INDEX_FILE" ] && { - export GIT_INDEX_FILE="$GIT_DIR/import-pk3-index" - cleanup_index=t -} - -# Extract the PK3 (the -n suppresses prompting in an edge case) -unzip -n -qq "$pk3path" -d "$GIT_WORK_TREE" || -die "couldn't extract PK3 contents" -cleanup_worktree=t - -# Note the refs and the common ancestor -master=refs/heads/master -ref=refs/heads/$branch -base=$(git merge-base $master $ref 2> /dev/null) || -base=$master - -# Figure out the parent commit -parent=\ -$(git rev-parse --verify -q $ref || git rev-parse --verify -q $base) || -die "couldn't determine parent commit" - -# Read the tree at base into index -git read-tree $base || -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" - -# Force reading of .gitignore files from cache, not the work tree -git ls-files --cached -z | -grep -z '\.gitignore$' | -git update-index --skip-worktree -z --stdin || -die "couldn't set up exclude patterns from index" - -# Add untracked files; to filter out generated files such as BSP, add -# them to .gitignore and push, --exclude-standard (and the above hack) -# takes 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" diff --git a/misc/tools/git-pk3-import b/misc/tools/git-pk3-import new file mode 100755 index 00000000..ee081d48 --- /dev/null +++ b/misc/tools/git-pk3-import @@ -0,0 +1,133 @@ +#!/bin/sh + +# git-pk3-import: 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 +} + +# Clean up on exit + +cleanup_index= +cleanup_worktree= + +cleanup() +{ + [ "$cleanup_index" ] && rm -f "$GIT_INDEX_FILE" + [ "$cleanup_worktree" ] && find "$GIT_WORK_TREE" -mindepth 1 -delete +} + +trap cleanup EXIT + +# Set up index file, makes testing easier +[ -z "$GIT_INDEX_FILE" ] && { + export GIT_INDEX_FILE="$GIT_DIR/pk3-import-index" + cleanup_index=t +} + +# Extract the PK3 (the -n suppresses prompting in an edge case) +unzip -n -qq "$pk3path" -d "$GIT_WORK_TREE" || +die "couldn't extract PK3 contents" +cleanup_worktree=t + +# Note the refs and the common ancestor +master=refs/heads/master +ref=refs/heads/$branch +base=$(git merge-base $master $ref 2> /dev/null) || +base=$master + +# Figure out the parent commit +parent=\ +$(git rev-parse --verify -q $ref || git rev-parse --verify -q $base) || +die "couldn't determine parent commit" + +# Read the tree at base into index +git read-tree $base || +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" + +# Force reading of .gitignore files from cache, not the work tree +git ls-files --cached -z | +grep -z '\.gitignore$' | +git update-index --skip-worktree -z --stdin || +die "couldn't set up exclude patterns from index" + +# Add untracked files; to filter out generated files such as BSP, add +# them to .gitignore and push, --exclude-standard (and the above hack) +# takes 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 "pk3-import: $pk3name" $ref $commit || +die "couldn't commit changes"