tools: Use require_clean_work_tree everywhere.

As described in the commit that added this function, this fixes one
quite annoying bug and one at least in-principle bug:

 * On Windows, the simple version (lacking `git update-index
   --refresh`) routinely gives false positives, making the tools
   that rely on it basically unusable.

 * If you have uncommitted changes in the index but manage to have
   the worktree nevevertheless match HEAD, the simple version will
   give a false negative and we'd blow away those changes.
This commit is contained in:
Greg Price 2020-03-25 18:27:15 -07:00 committed by Anders Kaseorg
parent daf357aaab
commit 4d17abee82
3 changed files with 15 additions and 19 deletions

View File

@ -1,12 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
if ! git diff-index --quiet HEAD; then this_file=$(readlink -f "${BASH_SOURCE[0]}")
echo "There are uncommitted changes:" # shellcheck source=lib/git-tools.bash
git status --short . "${this_file%/*}"/lib/git-tools.bash
echo "Doing nothing to avoid losing your work."
exit 1 require_clean_work_tree 'check out PR as branch'
fi
request_id="$1" request_id="$1"
remote=${2:-"upstream"} remote=${2:-"upstream"}

View File

@ -1,12 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
if ! git diff-index --quiet HEAD; then this_file=$(readlink -f "${BASH_SOURCE[0]}")
echo "There are uncommitted changes:" # shellcheck source=lib/git-tools.bash
git status --short . "${this_file%/*}"/lib/git-tools.bash
echo "Doing nothing to avoid losing your work."
exit 1 require_clean_work_tree 'check out PR as branch'
fi
request_id="$1" request_id="$1"
remote=${2:-"upstream"} remote=${2:-"upstream"}

View File

@ -39,13 +39,11 @@ if [ -z "$request_id" ]; then
usage usage
fi fi
if ! git diff-index --quiet HEAD; then this_file=$(readlink -f "${BASH_SOURCE[0]}")
set +x # shellcheck source=lib/git-tools.bash
echo "There are uncommitted changes:" . "${this_file%/*}"/lib/git-tools.bash
git status --short
echo "Doing nothing to avoid losing your work." require_clean_work_tree 'reset to PR'
exit 1
fi
if [ -z "$pseudo_remote" ]; then if [ -z "$pseudo_remote" ]; then
set -x set -x