diff options
author | Teddy Wing | 2018-02-20 23:18:49 +0100 |
---|---|---|
committer | Teddy Wing | 2018-02-20 23:18:49 +0100 |
commit | ed85526917c8b892c432be74c5fd60ceff4f3ba2 (patch) | |
tree | 513104228e2feb6964b14497ec19548a26e5c101 | |
parent | 60d936dfbaa259c6f04cf1361955e6087c3aef78 (diff) | |
download | git-branch-list-ed85526917c8b892c432be74c5fd60ceff4f3ba2.tar.bz2 |
git-branch-list: Verify ID is an integer before doing `checkout`
When running:
$ git branch-list 2
we want to ensure the argument "2" in the example above is an integer.
If so, we take it to represent a branch-list ID. Otherwise an error code
should be returned.
Thanks to Peter Ho on StackOverflow for the neat Bash integer test:
https://stackoverflow.com/questions/2210349/bash-test-whether-string-is-valid-as-an-integer/19116862#19116862
-rwxr-xr-x | git-branch-list | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/git-branch-list b/git-branch-list index bd85160..bf55624 100755 --- a/git-branch-list +++ b/git-branch-list @@ -93,7 +93,12 @@ case "$command" in exit $? ;; *) - # if $1 is an integer - checkout_branch "$1" + # If `$1` is an integer + if [ "$1" -eq "$1" ] 2>/dev/null; then + checkout_branch "$1" + else + exit 1 + fi + ;; esac |