diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java | 18 |
1 files changed, 15 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..22e1f98181 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 @@ -84,9 +89,10 @@ public class CommitConfig { * if the template file does not exists * @throws ConfigInvalidException * if a {@code commitEncoding} is specified and is invalid + * @since 6.0 */ @Nullable - public String getCommitTemplateContent() + public String getCommitTemplateContent(@NonNull Repository repository) throws FileNotFoundException, IOException, ConfigInvalidException { if (commitTemplatePath == null) { @@ -94,11 +100,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(); |