Domanda

On Mercurial if I want to merge a branch I always have to perform it in two steps:

hg merge my_branch
hg ci -m "I just merged my branch"

Is there a way in which I could do the same in a single command (having it aborted if conflicts are found)?

hg merge my_branch -ci "I merged my branch" 
È stato utile?

Soluzione 2

I would not advise to execute the two at the same operation. The main reason is, during a merge conflict, you will need to resolve it before committing. So when the first operation fails, you are left out with a state that requires another commit anyway.

If you need to do this, to simplify the ideal case workflow, at least create a script to handle the conflictual case and revert back to the starting revision, so that the user can merge and commit normally. But using a simple alias will cause you more trouble than help you, in the end.

Altri suggerimenti

Would hg merge my_branch && hg ci -m "I just merged my branch" be acceptable or do you need to call hg only once?

&& executes the following command only if the first one returns successfully.

Edit:

If you need the command as an alias with arguments, this gets a bit more complicated, as aliases do not accept arguments. You can use a function and alias it though:

branch_and_commit() { hg merge $1 && hg ci -m $2; } ; alias bac=branch_and_commit

You can then call it like this:

bac my_branch_id "this is the comment"

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top