Gitwatch: Add option to include a (truncated) diff in the commit message

Created on 28 Nov 2012  ·  7Comments  ·  Source: gitwatch/gitwatch

As implemented in a one-shot version at ibrahima/gitwatch@0163ec5, and pointed out by @ibrahima in the comments on that commit, it could be nice for some use cases to have the chance to include the diff in the commit message.

Leaving out things like file name, and truncating it to the standard 80-char max length of git "short" commit messages, that should go neatly with changes that usually only change one file.

The option might also catch the case of multiple files having been changed and not including the actual diff in that case but instead something like "Multiple files changed, diff omitted."

help wanted

Most helpful comment

@mlncn If you try my pull request https://github.com/gitwatch/gitwatch/pull/54 (git fetch origin pull/54/head:pr-54 && git checkout pr-54), you should be able to see the filenames (with a graph of the changes) as the commit message by using gitwatch -l 1 ~/myproject.

All 7 comments

you could implement an option switch (e.g. -d/--diff) to include this, and an additional switch to set after how many characters it should be truncated (should default to 80)

That seems like a sensible way to do it.

Last I checked there wasn't a _good_ way to do long option switches (--diff) in bash (there are a few reasonable ways, none of which I consider elegant but then bash scripting is rarely elegant ;) ). Since this is bash I would probably go for getopts and just do single character switches although there's a way to do long options which relies on nonstandard behavior or something like that. There's also GNU getopt which supports long options but that may be less portable solution and looks a little uglier. Anyway you probably don't care about all that at this point since up till now gitwatch does not take any options besides the path, but I guess it's up to you what you think about that. I have worked with getopts before, it's fairly straightforward and is a bash builtin.

I guess the other question is how to truncate and whether you want +- symbols to be included and whether you would want file names too. Maybe there could be a few options that add different components to the message (truncated diff, files changed, the current auto-commit message, etc).

We introduced some short options in the testing branch, using getopts in bash. But youre right, if there is no "good" way to use long options, the short ones will do for now.

For now, simply prepending the diff message before the rest of the commit message will do. Users can modify the script easily enough if they prefer a different kind of commit message. If you could pull the testing branch and add the option and handling there, that would be awesome :D

It looks like some significant progress was made on this. If someone wants to revisit this and get it wrapped up and finished, I'd be happy to consider merging in.

I'm actually looking for something similar, but want to only include the filename in the commit message. That's probably easier or there might already be a way to do that?

@dmusican I also want this feature, so I implemented it and created a pull request against your latest master branch for it: https://github.com/gitwatch/gitwatch/pull/54
Also, since you can set the number of lines that are displayed as a "git diff" vs "git diff --stat", using "-l 1" will cause the functionality someone tried implementing in an old pull request https://github.com/gitwatch/gitwatch/pull/23/commits/af28cf4a87c71cdb9da7046d40ea9542a4661f43

@mlncn If you try my pull request https://github.com/gitwatch/gitwatch/pull/54 (git fetch origin pull/54/head:pr-54 && git checkout pr-54), you should be able to see the filenames (with a graph of the changes) as the commit message by using gitwatch -l 1 ~/myproject.

Pull request merged. Many thanks, @shervinemami .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alwaysin picture Alwaysin  ·  8Comments

hongkongkiwi picture hongkongkiwi  ·  3Comments

miguelarauj1o picture miguelarauj1o  ·  7Comments

datag picture datag  ·  9Comments

euclio picture euclio  ·  3Comments