From 646d28a9e550d907fd8353527aaaa7d87b365e76 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 26 Feb 2018 22:05:00 +0300 Subject: [PATCH] Feat(status): Copy index and set GIT_INDEX_FILE to avoid touching .git --- all-status | 9 ++++++--- all-status-carefully | 15 --------------- git-status.sh | 19 +++++++++++++++++++ ls-status | 8 ++++++-- ls-status-carefully | 13 ------------- status-dirty | 2 +- status-dirty-carefully | 14 -------------- 7 files changed, 32 insertions(+), 48 deletions(-) delete mode 100755 all-status-carefully create mode 100755 git-status.sh delete mode 100755 ls-status-carefully delete mode 100755 status-dirty-carefully diff --git a/all-status b/all-status index 60ab248..102bf24 100755 --- a/all-status +++ b/all-status @@ -1,6 +1,9 @@ #! /bin/sh -prog_dir=`dirname "$0"` -"$prog_dir"/do-all \ +cd "`dirname \"$0\"`" && +prog_dir="`pwd`" && +export prog_dir + +exec "$prog_dir"/do-all \ 'test "$g" = "$d/.git" || continue; cd "$d" &&' \ - 'echo "----- $d -----" && git status --short --branch || exit 1' + 'echo "----- $d -----" && "$prog_dir"/git-status.sh --short --branch || exit 1' diff --git a/all-status-carefully b/all-status-carefully deleted file mode 100755 index d0bafa5..0000000 --- a/all-status-carefully +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/sh - -STMP="$HOME"/tmp/all-status-carefully.tmp -export STMP -trap 'exec rm -rf "$STMP"' 0 HUP INT QUIT TERM - -cd "`dirname \"$0\"`" && prog_dir="`pwd`" && -rm -rf "$STMP" && mkdir "$STMP" && - -"$prog_dir"/do-all \ - 'test "$g" = "$d/.git" || continue;' \ - 'rsync -aW --del --protocol=28 "$d" "$STMP" && cd "$STMP/$b" &&' \ - '( test -n "`git status --short`" ||' \ - 'git status --branch --short | grep -q "ahead\|behind" ) &&' \ - 'echo "----- $d -----" && git status --short --branch' diff --git a/git-status.sh b/git-status.sh new file mode 100755 index 0000000..ddab464 --- /dev/null +++ b/git-status.sh @@ -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" diff --git a/ls-status b/ls-status index f90ae41..6892f2b 100755 --- a/ls-status +++ b/ls-status @@ -1,5 +1,9 @@ #! /bin/sh -exec "`dirname \"$0\"`"/do-all \ +cd "`dirname \"$0\"`" && +prog_dir="`pwd`" && +export prog_dir + +exec "$prog_dir"/do-all \ 'test "$g" = "$d/.git" || continue; cd "$d" &&' \ - 'test -n "`git status --short`" && echo "$d"' + 'test -n "`"$prog_dir"/git-status.sh --short`" && echo "$d"' diff --git a/ls-status-carefully b/ls-status-carefully deleted file mode 100755 index cecdfa4..0000000 --- a/ls-status-carefully +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh - -LSTMP="$HOME"/tmp/ls-status-carefully.tmp -export LSTMP -trap 'exec rm -rf "$LSTMP"' 0 HUP INT QUIT TERM - -cd "`dirname \"$0\"`" && prog_dir="`pwd`" && -rm -rf "$LSTMP" && mkdir "$LSTMP" && - -"$prog_dir"/do-all \ - 'test "$g" = "$d/.git" || continue;' \ - 'rsync -aW --del --protocol=28 "$d" "$LSTMP" && cd "$LSTMP/$b" &&' \ - 'test -n "`git status --short`" && echo "$d"' diff --git a/status-dirty b/status-dirty index c8a199b..b0db2a8 100755 --- a/status-dirty +++ b/status-dirty @@ -4,5 +4,5 @@ prog_dir=`dirname "$0"` for d in `"$prog_dir"/ls-dirty` do echo "----- $d -----" && cd "$d" && - git status || exit 1 + "$prog_dir"/git-status.sh || exit 1 done diff --git a/status-dirty-carefully b/status-dirty-carefully deleted file mode 100755 index 4298b09..0000000 --- a/status-dirty-carefully +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh - -STMP="$HOME"/tmp/status-dirty-carefully.tmp -export STMP -trap 'exec rm -rf "$STMP"' 0 HUP INT QUIT TERM - -cd "`dirname \"$0\"`" && prog_dir="`pwd`" && -rm -rf "$STMP" && mkdir "$STMP" && - -for d in `"$prog_dir"/ls-dirty` -do - echo "----- $d -----" && rsync -aW --del --protocol=28 "$d" "$STMP" && - cd "$STMP/`basename \"$d\"`" && git status --branch -done -- 2.39.5