Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit --verbose equivalent in mercurial?

Tags:

git

mercurial

In git, I can do "git commit --verbose" to show me a diff right there in the message editor. I don't see any option for it in mercurial. Is there a mercurial plugin to show me a diff in the message editor or anything similar?

like image 351
Mu Mind Avatar asked Oct 27 '12 04:10

Mu Mind


3 Answers

Short answer: There is no git commit --verbose equivalent in mercurial, but it's possible to hack it in.

The edit text is hard-coded in the mercurial source, so no plugin or configuration can directly change it.

The best you can do is to hack the ui.editor setting in your hgrc to add text into the editor directly. I made a script called hg-commit-editor:

#!/bin/sh
echo 'HG: ------------------------ >8 ------------------------' >> $1
hg diff >> $1
editor $1
exit $?

and then set it as my commit editor in my hgrc:

[ui]
editor = hg-commit-editor

This appends the output of "hg diff" to the bottom of the edit text file after a special line (source) so it's not included as part of the commit message.

like image 186
Mu Mind Avatar answered Nov 08 '22 09:11

Mu Mind


Not directly but you could combine:

  • "Mercurial: multiline commit message on the command line?"
    hg commit -l filename.txt

    (that would commit without opening the editor)
  • "How do I customize the 'commit message file' generated by hg commit?"
    Using the text you just generated as a commit message you would see when the editor comes up when you hg commit.
    with:
  • "In Mercurial (hg), how do you see a list of files that will be pushed if an “hg push” is issued?"
    hg -q outgoing --style ~/out-style.txt | sort -u
    or:
    hg outgoing -v |grep files: |cut -c 14- |tr ' ' '\n' |sort -u

So: generating a file with the right information in it (list of files to be pushed) as the commit message.

like image 31
VonC Avatar answered Nov 08 '22 07:11

VonC


The easiest solution is to download this (use the raw link on the left hand side), put it in your $PATH, then set HGEDITOR environment variable to this script.

When doing hg commit, you'll see the diff in a separate window.

See also https://www.mercurial-scm.org/wiki/hgeditor

@Mu Mind's script should still work, and probably preferable if you want it to behave as close as git commit --verbose.

like image 1
yegle Avatar answered Nov 08 '22 09:11

yegle