This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-scm.git


The following commit(s) were added to refs/heads/master by this push:
     new 544918631 Ask git log to transcode changelog output to the platform 
charset
544918631 is described below

commit 544918631cd352b4db655ab617b58995af6f8c17
Author: Arturo Bernal <[email protected]>
AuthorDate: Fri Nov 20 12:15:12 2026 +0100

    Ask git log to transcode changelog output to the platform charset
    
    git stores commit messages as UTF-8 internally, but the process output is
    read back with CommandLineUtils.executeCommandLine(), which decodes it
    using the JVM's default charset with no override available. On any
    platform whose default charset isn't UTF-8, non-ASCII commit messages in
    the generated changelog get corrupted.
    
    Pass --encoding=<platform charset> to git log so it transcodes its UTF-8
    output into whatever charset will actually be used to decode it.
    
    Fixes #1118
---
 .../command/changelog/GitChangeLogCommand.java     |  6 ++++
 .../command/changelog/GitChangeLogCommandTest.java | 37 +++++++++++++++-------
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
index 4b263b1e3..d951aee73 100644
--- 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
+++ 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
@@ -19,6 +19,7 @@
 package org.apache.maven.scm.provider.git.gitexe.command.changelog;
 
 import java.io.File;
+import java.nio.charset.Charset;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.TimeZone;
@@ -259,6 +260,11 @@ static Commandline createCommandLine(
         cl.createArg().setValue("--decorate=short");
         cl.createArg().setValue("--raw");
         cl.createArg().setValue("--no-merges");
+        // git stores commit messages as UTF-8 internally; ask it to transcode 
its output to whatever
+        // charset the JVM will use to decode the process stream 
(CommandLineUtils.executeCommandLine()
+        // reads it using Charset.defaultCharset()), or non-ASCII characters 
get corrupted on platforms
+        // whose default charset isn't UTF-8.
+        cl.createArg().setValue("--encoding=" + 
Charset.defaultCharset().name());
 
         if (startDate != null || endDate != null) {
             if (startDate != null) {
diff --git 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
index 2e0a556e7..131bd2aee 100644
--- 
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
+++ 
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
@@ -19,6 +19,7 @@
 package org.apache.maven.scm.provider.git.gitexe.command.changelog;
 
 import java.io.File;
+import java.nio.charset.Charset;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -37,6 +38,9 @@
  *
  */
 class GitChangeLogCommandTest extends ScmTestCase {
+    private static final String ENCODING_ARG =
+            "--encoding=" + Charset.defaultCharset().name();
+
     private File workingDirectory;
 
     @BeforeEach
@@ -53,7 +57,8 @@ void testCommandLineNoDates() throws Exception {
                 (Date) null,
                 (Date) null,
                 40,
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso --max-count=40 -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " --date=iso --max-count=40 -- .");
     }
 
     @Test
@@ -63,7 +68,7 @@ void testCommandLineNoDatesLimitedCount() throws Exception {
                 null,
                 (Date) null,
                 (Date) null,
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG + " --date=iso -- .");
     }
 
     @Test
@@ -76,7 +81,8 @@ void testCommandLineWithDates() throws Exception {
                 null,
                 startDate,
                 endDate,
-                "git log --format=medium --decorate=short --raw --no-merges 
\"--since=2003-09-10 00:00:00 +0000\" \"--until=2007-10-10 00:00:00 +0000\" 
--date=iso -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " \"--since=2003-09-10 00:00:00 +0000\" 
\"--until=2007-10-10 00:00:00 +0000\" --date=iso -- .");
     }
 
     @Test
@@ -88,7 +94,8 @@ void testCommandLineStartDateOnly() throws Exception {
                 null,
                 startDate,
                 null,
-                "git log --format=medium --decorate=short --raw --no-merges 
\"--since=2003-09-10 01:01:01 +0000\" --date=iso -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " \"--since=2003-09-10 01:01:01 +0000\" --date=iso 
-- .");
     }
 
     @Test
@@ -101,7 +108,8 @@ void testCommandLineDateFormat() throws Exception {
                 null,
                 startDate,
                 endDate,
-                "git log --format=medium --decorate=short --raw --no-merges 
\"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" 
--date=iso -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " \"--since=2003-09-10 01:01:01 +0000\" 
\"--until=2005-11-13 23:23:23 +0000\" --date=iso -- .");
     }
 
     @Test
@@ -116,7 +124,8 @@ void testCommandLineDateVersionRanges() throws Exception {
                 endDate,
                 new ScmRevision("1"),
                 new ScmRevision("10"),
-                "git log --format=medium --decorate=short --raw --no-merges 
\"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" 
--date=iso 1..10 -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " \"--since=2003-09-10 01:01:01 +0000\" 
\"--until=2005-11-13 23:23:23 +0000\" --date=iso 1..10 -- .");
     }
 
     @Test
@@ -129,7 +138,8 @@ void testCommandLineEndDateOnly() throws Exception {
                 null,
                 null,
                 endDate,
-                "git log --format=medium --decorate=short --raw --no-merges 
\"--until=2003-11-10 00:00:00 +0000\" --date=iso -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " \"--until=2003-11-10 00:00:00 +0000\" --date=iso 
-- .");
     }
 
     @Test
@@ -139,7 +149,8 @@ void testCommandLineWithBranchNoDates() throws Exception {
                 new ScmBranch("my-test-branch"),
                 (Date) null,
                 (Date) null,
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso my-test-branch -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " --date=iso my-test-branch -- .");
     }
 
     @Test
@@ -149,7 +160,7 @@ void testCommandLineWithStartVersion() throws Exception {
                 null,
                 new ScmRevision("1"),
                 null,
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso 1.. -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG + " --date=iso 1.. -- .");
     }
 
     @Test
@@ -159,7 +170,8 @@ void testCommandLineWithStartVersionAndEndVersion() throws 
Exception {
                 null,
                 new ScmRevision("1"),
                 new ScmRevision("10"),
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso 1..10 -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " --date=iso 1..10 -- .");
     }
 
     @Test
@@ -169,7 +181,7 @@ void testCommandLineWithStartVersionAndEndVersionEquals() 
throws Exception {
                 null,
                 new ScmRevision("1"),
                 new ScmRevision("1"),
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso 1..1 -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG + " --date=iso 1..1 -- .");
     }
 
     @Test
@@ -179,7 +191,8 @@ void 
testCommandLineWithStartVersionAndEndVersionAndBranch() throws Exception {
                 new ScmBranch("my-test-branch"),
                 new ScmRevision("1"),
                 new ScmRevision("10"),
-                "git log --format=medium --decorate=short --raw --no-merges 
--date=iso 1..10 my-test-branch -- .");
+                "git log --format=medium --decorate=short --raw --no-merges " 
+ ENCODING_ARG
+                        + " --date=iso 1..10 my-test-branch -- .");
     }
 
     // ----------------------------------------------------------------------

Reply via email to