This is an archive of the discontinued Mercurial Phabricator instance.

amend: exit 0 if there are no changes
AbandonedPublic

Authored by spectral on Apr 9 2018, 6:09 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

It's useful for writing some scripts or shell aliases if hg amend doesn't
abort the series of commands if there's nothing to amend. Users can then have
something like "alias amendevo='hg amend && hg evolve -a'" to amend and evolve
in one step.

To do this otherwise would require something like this:

alias amendevo='[[ -z "$(hg status -mar)" ]] && hg amend && hg evolve -a'

While that's not too onerous, it's not immediately obvious to most that this is
what would have to be done, so it's a small hurdle that users either have to
spend time to figure out on their own or ask about.

A similar change was made to hg evolve recently, for similar reasons.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

spectral created this revision.Apr 9 2018, 6:09 PM
quark added a subscriber: quark.Apr 9 2018, 7:37 PM

Returning 1 is actually more consistent with other core commands like pull, push, commit. See https://www.mercurial-scm.org/pipermail/mercurial-devel/2012-January/037711.html. Scripts should be updated to use $? explicitly.

In D3209#51512, @quark wrote:

Returning 1 is actually more consistent with other core commands like pull, push, commit. See https://www.mercurial-scm.org/pipermail/mercurial-devel/2012-January/037711.html. Scripts should be updated to use $? explicitly.

I'm not sure how scripts can be updated to use $? explicitly. Mercurial exits 1 in many situations:

  • nothing found
  • hg verify, if there's any problems
  • unresolved conflicts when updating/rebasing/whatever
  • histedit 'edit' seems to dump you back into a terminal with exit status 1
  • MQ seems to use it a lot
  • I think a few others?

Yes, none of these apply to hg amend, so doing something like hg amend; [[ $? -eq 1 ]] && hg evolve -a is feasible, but again, feels really weird and non-discoverable. :/

I also see a few cases that return 2, mostly in MQ stuff (though there is one case in test-bookmarks-pushpull.t that's a little odd). There's obviously the "255" return whenever there's a major problem.

I'm not too tied to the patch and can abandon it if people feel it's incorrect.

quark added a comment.Apr 9 2018, 9:51 PM

I think it depends on what scripts want to do. I guess mpm's original point is, suppose you have a build script, or something that should do nothing if nothing changed, then hg amend && build_script just works as expected. If amend returns 0, then it'd be more complex to detect "nothing changed" case.

spectral abandoned this revision.Feb 6 2019, 6:19 PM