diff options
author | Julian Ruppel <julian.ruppel@sap.com> | 2021-09-18 15:02:03 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-11-22 02:22:03 -0500 |
commit | 00f6fe72a744af56364b88fe2b59b8e7ab6d6ce9 (patch) | |
tree | a36d61d6fa0241512e13defbf67241a53b9335ec /org.eclipse.jgit/src/org/eclipse/jgit/lib | |
parent | 2e2a3642c3775d0cd3c7184fd9b45a53dcb47629 (diff) | |
download | jgit-00f6fe72a744af56364b88fe2b59b8e7ab6d6ce9.tar.gz jgit-00f6fe72a744af56364b88fe2b59b8e7ab6d6ce9.zip |
Support commit.template config property
Fixes an issue that commit template file could not be found if it has a
relative path instead of absolute path.
Relative path is probably common if git config --local is used.
Bug: 446355
Change-Id: I8ddf2be672647be825fd9c01af82809d31bb8356
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java index e4e7cd6e03..5e70556a3c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java @@ -18,6 +18,8 @@ import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.text.MessageFormat; + +import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; @@ -77,6 +79,9 @@ public class CommitConfig { * {@code commit.template}. If no {@code i18n.commitEncoding} is specified, * UTF-8 fallback is used. * + * @param repository + * to resolve relative path in local git repo config + * * @return content of the commit template or {@code null} if not present. * @throws IOException * if the template file can not be read @@ -86,7 +91,7 @@ public class CommitConfig { * if a {@code commitEncoding} is specified and is invalid */ @Nullable - public String getCommitTemplateContent() + public String getCommitTemplateContent(@NonNull Repository repository) throws FileNotFoundException, IOException, ConfigInvalidException { if (commitTemplatePath == null) { @@ -94,11 +99,17 @@ public class CommitConfig { } File commitTemplateFile; + FS fileSystem = repository.getFS(); if (commitTemplatePath.startsWith("~/")) { //$NON-NLS-1$ - commitTemplateFile = FS.DETECTED.resolve(FS.DETECTED.userHome(), + commitTemplateFile = fileSystem.resolve(fileSystem.userHome(), commitTemplatePath.substring(2)); } else { - commitTemplateFile = FS.DETECTED.resolve(null, commitTemplatePath); + commitTemplateFile = fileSystem.resolve(null, commitTemplatePath); + } + if (!commitTemplateFile.isAbsolute()) { + commitTemplateFile = fileSystem.resolve( + repository.getWorkTree().getAbsoluteFile(), + commitTemplatePath); } Charset commitMessageEncoding = getEncoding(); |