fboender / multi-git-status

Show uncommitted, untracked and unpushed changes for multiple Git repos
MIT License
470 stars 73 forks source link

Fix shellcheck SC2236 -n/-z errors #18

Closed bexelbie closed 5 years ago

bexelbie commented 5 years ago

This is stylistic. If we want to keep this style, we should ignore SC2236


In mgitstatus line 43:
while [ ! -z "$1" ]; do
        ^-- SC2236: Use -n instead of ! -z.

In mgitstatus line 225:
    if [ ! -z "$NEEDS_PUSH_BRANCHES" ] && [ "$NO_PUSH" -eq 0 ]; then
         ^-- SC2236: Use -n instead of ! -z.

In mgitstatus line 228:
    if [ ! -z "$NEEDS_PULL_BRANCHES" ] && [ "$NO_PULL" -eq 0 ]; then
         ^-- SC2236: Use -n instead of ! -z.

In mgitstatus line 231:
    if [ ! -z "$NEEDS_UPSTREAM_BRANCHES" ] && [ "$NO_UPSTREAM" -eq 0 ]; then
         ^-- SC2236: Use -n instead of ! -z.

For more information:
  https://www.shellcheck.net/wiki/SC2236 -- Use -n instead of ! -z.
fboender commented 5 years ago

According to POSIX, -n is:

-n  string
    True if the length of string is non-zero; otherwise, false.

Whilst ! is documented as:

!  expression
    True if expression is false. False if expression is true.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

In my experience, ! works well across many different shells, but if your experience is that -n is actually more compatible, we should go with that. Otherwise, I think we should ignore shellcheck on this one.

fboender commented 5 years ago

Oh wait, it's early and I need more coffee... -n would probably work here, although I remember an edge case which is why I went with !.. let met dig up my memory.

fboender commented 5 years ago

This should work just fine, thanks!