Skip to content

Instantly share code, notes, and snippets.

@NonLogicalDev
Last active February 4, 2022 21:59
Show Gist options
  • Save NonLogicalDev/8b2d77563688f6495f233704e5edd947 to your computer and use it in GitHub Desktop.
Save NonLogicalDev/8b2d77563688f6495f233704e5edd947 to your computer and use it in GitHub Desktop.
stg-checked-refresh-index() {
#: stg-checked-refresh-index
#: `stg refresh --index` but with diff preview and confirmation
#:
TARGET_PATCH=$(stg top)
git diff --cached -u --stat
git --no-pager diff --cached --stat
echo
echo ">> Applying diff to patch: $TARGET_PATCH (sha:$(git rev-parse --short $(stg id $TARGET_PATCH)))"
if ( read -q 'choice?$$ Confirm? ' ); then
echo
echo ">> [applying...]"
( set -x; stg refresh --index -p $TARGET_PATCH; )
echo ">> Verifying Git Status:"
git status -s
else
echo
echo ">> [cancelled]"
fi
}
stg-checked-refresh-update() {
#: stg-checked-refresh-update
#: `stg refresh` but with diff preview and confirmation
#:
TARGET_PATCH=$(stg top)
# Display difference between head and updated files
git diff -u --stat HEAD -- "$@"
git --no-pager diff --stat HEAD -- "$@"
echo
echo ">> Applying diff to patch: $TARGET_PATCH (sha:$(git rev-parse --short $(stg id $TARGET_PATCH)))"
if ( read -q 'choice?$$ Confirm? ' ); then
echo
echo ">> [applying...]"
( set -x; stg refresh -p $TARGET_PATCH -- "$@" ; )
echo ">> Verifying Git Status:"
git status -s
else
echo
echo ">> [cancelled]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment