]> git.phdru.name Git - git-scripts.git/blobdiff - git-status.sh
Feat(status): Copy index and set GIT_INDEX_FILE to avoid touching .git
[git-scripts.git] / git-status.sh
diff --git a/git-status.sh b/git-status.sh
new file mode 100755 (executable)
index 0000000..ddab464
--- /dev/null
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+STMP="$HOME"/tmp/git-status.tmp
+export STMP
+trap 'exec rm -rf "$STMP"' 0 HUP INT QUIT TERM
+rm -rf "$STMP" && mkdir "$STMP" &&
+
+GIT_INDEX_FILE="$STMP"/index &&
+export GIT_INDEX_FILE &&
+
+if [ -d .git -a -f .git/index ]; then
+   cp -p .git/index $GIT_INDEX_FILE
+else
+   echo "$0: `pwd` is not a git directory" >&2
+   exit 1
+fi &&
+
+git status "$@" &&
+exec rm -rf "$STMP"