bin/git-dife: allow diffing untracked files tracked remotely

This commit is contained in:
xeruf 2021-11-23 14:56:38 +01:00
parent 3c34126214
commit 02c959ce70
2 changed files with 13 additions and 2 deletions

8
.local/bin/scripts/git-dife Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# Diff untracked file to a tracked version in another branch (default upstream)
file="$1"
test -e "$file" && rooted=false || rooted=true
root="$($rooted && echo "$(git root)/")$file"
test ! -e "$root" && echo "No such file: $file" >&2 && exit 1
upstream="${2:-@{u}}"
git show "$upstream:$($rooted || echo "./")$file" | dif --label "$1 $(stat "$1" --format '%y')" --label "$upstream" "$root" -

View File

@ -8,9 +8,12 @@ do
if test -e "$f/.git" || test -e "$f/packed-refs" if test -e "$f/.git" || test -e "$f/packed-refs"
then echo -n "Force delete git project $f? " then echo -n "Force delete git project $f? "
read answer read answer
test "$answer" = "y" && $elevate rm -rf "$f" test "$answer" = "y" &&
$elevate rm -rf "$f"
else find "$f" -maxdepth 4 -empty -printf "Removing empty %p\n" -delete else find "$f" -maxdepth 4 -empty -printf "Removing empty %p\n" -delete
test -e "$f" && echo -n "$f " >&2 && $elevate rm -rI "$f" test -e "$f" &&
echo -n "$f ($(ls -A $f | head -3 | paste -s -d' ')) " >&2 &&
$elevate rm -rI "$f"
fi fi
else $elevate rm -i "$f" else $elevate rm -i "$f"
fi fi