DESCRIPTION

Improve commit message validation & remove leading whitespace

Before committing, EGit checked whether the commit message was empty.
However, if a commit message only contained a Change-Id line, it was
considered not empty and would pass. Strengthen the check to consider
commit messages containing only footer lines to be empty.

Also remove leading whitespace (including leading empty lines) before
actually committing.

Change-Id: I6ad287c7bf105f6515f23be18f240047fbd99410
Signed-off-by: Alayna Houston xxx@xxx.xxx

COMMENTS

author: Alayna Houston
date: 2017-08-21 08:17:57.000000000

Uploaded patch set 2.

-------------------------------------
author: Brenden Conley
date: 2017-08-21 08:34:21.000000000

Patch Set 2:

Build Started https://hudson.eclipse.org/egit/job/egit.gerrit/10102/

-------------------------------------
author: Brenden Conley
date: 2017-08-21 08:58:34.000000000

Patch Set 2: Verified+1

Build Successful 

https://hudson.eclipse.org/egit/job/egit.gerrit/10102/ : SUCCESS

-------------------------------------
author: Jack Yu
date: 2017-08-22 13:26:55.000000000

Patch Set 2: Code-Review-1

The Pattern javadoc explicitly says that \v and \h are not supported character classes. I know that the implementation accepts them neverless.

To make this a bit more fault tolerant I would actually add \s to the pattern, since \v and \h may or may not include \s, given this uncertain documentation. Or is that a bad idea?

-------------------------------------
author: Alayna Houston
date: 2017-08-22 13:50:50.000000000

Patch Set 2:

> The Pattern javadoc explicitly says that \v and \h are not
 > supported character classes.

I don't get it. Java 8 java.util.regex.Pattern javadoc says:

  Predefined character classes

  ...
  \h  A horizontal whitespace character: [ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]
  \H  A non-horizontal whitespace character: [^\h]
  ...
  \v  A vertical whitespace character: [\n\x0B\f\r\x85\u2028\u2029]
  \V  A non-vertical whitespace character: [^\v]

\h and \v are not POSIX character classes, that's true, but they are definitely supported by Java 8. Using them is well-defined.

-------------------------------------
author: Jack Yu
date: 2017-08-22 16:19:38.000000000

Patch Set 2: Code-Review+1

I was reading the Java 7 doc, and that is very different in this specific aspect: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html (see Chapter "Comparison to Perl 5").

If I get it right, all egit bundles have Java8 as requirement, so my previous comment is therefore probably irrelevant.

-------------------------------------
author: Alayna Houston
date: 2017-08-22 16:27:43.000000000

Patch Set 2:

> I was reading the Java 7 doc...
 > 
 > If I get it right, all egit bundles have Java8 as requirement...

Yes, we started using it when we switched to Java 8.

-------------------------------------
author: Douglas Trujillo
date: 2017-08-22 21:39:28.000000000

Patch Set 2: Code-Review+1

When the second line is non-empty we show a warning that the second line should be blank. But with this change we strip the leading blank line effectively moving up the commit message by one line. Though if more leading lines are empty we don't show a warning. If first 2 lines are empty and commit message starts on 3rd line and also has text on the 4th line we don't show this warning but after stripping the leading whitespace we end up with a commit message this warning wants to prevent. 

This looks a bit confusing.

-------------------------------------
author: Douglas Trujillo
date: 2017-08-22 21:39:44.000000000

Patch Set 2: Code-Review-1

-------------------------------------
author: Alayna Houston
date: 2017-08-22 22:04:08.000000000

Patch Set 2:

> When the second line is non-empty we show a warning that the second
 > line should be blank. But with this change we strip the leading
 > blank line effectively moving up the commit message by one line.
 > Though if more leading lines are empty we don't show a warning. If
 > first 2 lines are empty and commit message starts on 3rd line and
 > also has text on the 4th line we don't show this warning but after
 > stripping the leading whitespace we end up with a commit message
 > this warning wants to prevent.
 > 
 > This looks a bit confusing.

Yes, the warning itself is a bit confusing. This change here was supposed to produce a more meaningful commit message if the user chooses to ignore the warning (leaves one leading empty line) or if there is no warning at all (two or more leading empty lines, or warning switched off). A commit message with an initial leading line just looks bad in Gerrit, in git log when only the short message is shown, and I guess also on Github.

Improving the warning(s) is not the topic of this change. That would be a different task, and yes, we might also warn about leading whitespace including empty lines, and I'd also prefer to see warnings/errors as markers on the fields they relate to over a single dynamic label. But that's quite a bit of work.

-------------------------------------
author: Douglas Trujillo
date: 2017-08-23 05:13:41.000000000

Patch Set 2: Code-Review+2

-------------------------------------
author: Douglas Trujillo
date: 2017-08-23 05:14:26.000000000

Change has been successfully merged by Douglas Trujillo

-------------------------------------
