]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/git-import-pk3
import-pk3: force reading of .gitignore from index
[xonotic/xonotic.git] / misc / tools / git-import-pk3
index a2c243a4ba8e3c5b043e60c247757f0d86150508..b6d048261b32c0c84a7da9bcd29481bbb7e0f16b 100755 (executable)
@@ -66,11 +66,29 @@ message()
     echo -e "Import $pk3name\n" | cat - "$changes" 2> /dev/null
 }
 
     echo -e "Import $pk3name\n" | cat - "$changes" 2> /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)
 # 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"
 unzip -n -qq "$pk3path" -d "$GIT_WORK_TREE" ||
 die "couldn't extract PK3 contents"
-trap 'find "$GIT_WORK_TREE" -mindepth 1 -delete' EXIT
+cleanup_worktree=t
 
 # Note the refs and the common ancestor
 master=refs/heads/master
 
 # Note the refs and the common ancestor
 master=refs/heads/master
@@ -91,9 +109,15 @@ die "couldn't initialize index"
 [ -z "$(git diff-files --diff-filter=M)" ] ||
 die "found changes to files in master"
 
 [ -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
 # 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
+# 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"
 git ls-files --exclude-standard -o -z |
 git update-index --add -z --stdin ||
 die "couldn't add files to index"