obsidian-git
obsidian-git copied to clipboard
Author in commit message Add Support for {{author}} in commit message
trafficstars
Description
This Pull Request introduces a new feature to Obsidian-Git, addressing the need to specify the author in commit messages. The enhancement is designed to support collaborative environments, allowing users to easily identify contributors in the commit history.
Changes Made
{{author}} Variable Implementation:
The author's name is dynamically retrieved from the Git configuration using the following code snippet:
if (template.includes("{{author}}")) {
const author = await this.plugin.gitManager.getConfig("user.name");
template = template.replace("{{author}}", author);
}
Updated getConfig Function:
To ensure compatibility and obtain the user.name on various machines, the getConfig function has been updated to first fetch the local configuration and then the global configuration. The code modification is as follows:
async getConfig(path: string): Promise<any> {
const globalConfig = await this.git.listConfig("global", (err) =>
this.onError(err)
);
const localConfig = await this.git.listConfig("local", (err) =>
this.onError(err)
);
const config = { ...globalConfig.all, ...localConfig.all };
return config[path];
}
Fix #691