Well, much depends on how paranoid you want to be.
One obvious thing you could do is verify that there is at least, or exactly, one argument to the function, so that $1
expands to something:
case $# in
1) ;;
*) echo "usage: newTest <name>" 1>&2; return 1;;
esac
Another is to make sure the branch name is valid. Per git-check-ref-format
:
local ref
ref=$(git check-ref-format --normalize "refs/heads/staging-test-$1") ||
{ echo "'staging-test-$1' is not a valid branch name" 1>&2; return 1; }
although then you probably want to strip refs/heads/ off again:
ref=${ref#refs/heads/}
after which you can use $ref
to avoid repeating the staging-test-
part.
Then: what if that branch name already exists? Is that an error, or should it be replaced? (To make it an error, check for git checkout -b
failure, for instance.)
Then: what if stash or rebase fails? You say "there should never be changes", but presumably the point of saving and applying the stash is that there are some changes. It's not really clear to me what updateDev
is intended to do. It does not check what the current branch is, it simply rebases the current branch (whatever it is) onto development
using -X theirs
(which means keep "our" version of everything).
Moreover, suppose there are no changes to stash, but there is already an existing stash. In this case, git stash
will exit successfully after printing No local changes to save
. The updateDev
script will then run the rebase, and assuming it succeeds, will pop (apply and drop) the top-most existing stash. This is almost certainly not a good thing.
Last: what if git checkout -b
and/or git push
fail? (E.g., due to running out of disk space or something equally terrible, or simply because the name supplied already existed.)