Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] git commit --amend -m "": errors now: error: switch `m' requires a value #725

Closed
blueyed opened this issue Dec 9, 2014 · 6 comments
Labels

Comments

@blueyed
Copy link
Contributor

blueyed commented Dec 9, 2014

In hub 2, git commit --amend -m "" stopped working:

error: switch `m' requires a value
usage: git commit [options] [--] <pathspec>...

git version 2.1.0
hub version 2.2.0-preview1-66-ga16a121

Using git directly works.

It seems to not bypass empty shell arguments properly.

@blueyed blueyed changed the title git commit --amend -m "": errors now: error: switch `m' requires a value [v2] git commit --amend -m "": errors now: error: switch `m' requires a value Dec 9, 2014
@mislav
Copy link
Owner

mislav commented Dec 9, 2014

Good catch, thanks for letting us know!

Git itself is also supposed to fail when an empty commit message is given, but its error message should be: "Aborting commit due to empty commit message." This is obviously a case of us not forwarding command-line arguments correctly.

@blueyed
Copy link
Contributor Author

blueyed commented Dec 9, 2014

Git does not fail, but re-uses the last message (at least with --amend).

I am using this alias/function, which results in an empty arg always at the end:

alias gcma='noglob _nomatch command_with_files "git commit --amend -m"'
command_with_files() {
  local cmd=$1; shift
  # Shift existing files/dirs from the beginning of args.
  files=()
  while (( $# > 0 )) && [[ -e $1 ]]; do
    files+=($1)
    shift
  done

  printf '%s\n' $=cmd "$*" $files
  $=cmd "$*" $files
}

owenthereal added a commit that referenced this issue Dec 9, 2014
Empty string arguments are removed when building an executable command, causing problems like #725. However, we need to remove empty string arguments constructed from the commands layer, e.g., https://github.com/github/hub/blob/master/commands/browse.go#L112. We fix it by moving the removal logic to `Args.ToCmd`.
@owenthereal
Copy link
Contributor

Good catch! I attempted a fix in #727. The Args file is a bit of a mess now. I already have a better design in mind. Will do that in another PR.

@owenthereal owenthereal added the bug label Dec 9, 2014
@mislav
Copy link
Owner

mislav commented Dec 10, 2014

Git does not fail, but re-uses the last message (at least with --amend).

You can also try git commit --amend -C HEAD

@blueyed
Copy link
Contributor Author

blueyed commented Dec 10, 2014

Yes, and for that particular case git commit --amend --no-edit works also.

But the point of my alias is to provide an optional argument (which could be fixed/worked around), but that wouldn't have shown this bug.. ;)

@owenthereal
Copy link
Contributor

@blueyed The fixes have been merged into master. Please update. I'm closing the issue. Feel free to reopen if it still happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants