From f8459202b8b4742f86a0b3d803519a74334efba6 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:59:51 +0200 Subject: [PATCH 01/19] feat: add functions to cli.ts --- src/git/cli.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/git/cli.ts b/src/git/cli.ts index c53cb5ad..c101c075 100644 --- a/src/git/cli.ts +++ b/src/git/cli.ts @@ -88,3 +88,36 @@ export async function getChanges() { } return allChanges; } + + +/** + * Get a value from the Git config. + * + * The CLI will assume local (project) project by default. + */ +export async function _getConfigValue(options: string[]) { + const cmd = "config" + + const { stdout, stderr } = await _execute( + getWorkspaceFolder(), + cmd, + options + ); + + if (stderr) { + console.debug(`stderr for 'git ${cmd}' command:`, stderr); + } + + return stdout +} + +/** + * Get the configured value for a commit template path if set, or empty string. + */ +export async function getCommitTemplateName() { + try { + return await _getConfigValue(['commit.template']) + } catch (_e) { + return "" + } +} From 22edfb25a9b755b364eac427738bf2b75b8c5d76 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 12:00:03 +0200 Subject: [PATCH 02/19] feat: test function in extension.ts --- src/extension.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 7ec283ca..d4beb9b9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,6 +7,7 @@ import * as vscode from "vscode"; import { API } from "./api/git"; import { makeAndFillCommitMsg } from "./autofill"; +import { getCommitTemplateName } from "./git/cli"; import { getGitExtension } from "./gitExtension"; function _validateFoundRepos(git: API) { @@ -57,9 +58,38 @@ async function _handleRepos(git: API, sourceControl: any) { */ async function _handleRepo(git: API) { const targetRepo = git.repositories[0]; + await makeAndFillCommitMsg(targetRepo); } +async function _autofill(uri?: string) { + const git = getGitExtension(); + + if (!git) { + vscode.window.showErrorMessage("Unable to load Git Extension"); + return; + } + + if (git.repositories.length === 0) { + vscode.window.showErrorMessage( + "No repos found. Please open a repo or run git init then try this extension again." + ); + return; + } + + vscode.commands.executeCommand("workbench.view.scm"); + + if (uri) { + _handleRepos(git, uri); + } else { + _handleRepo(git); + } + + const templateName = await getCommitTemplateName() + console.debug(templateName) + +} + /** * Choose the relevant repo and apply autofill logic on files there. */ From 7021331d89cc8dc94f69129306729da6606ccd76 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 20:15:19 +0200 Subject: [PATCH 03/19] update extension.ts --- src/extension.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index d4beb9b9..695fea49 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,6 @@ import * as vscode from "vscode"; import { API } from "./api/git"; import { makeAndFillCommitMsg } from "./autofill"; -import { getCommitTemplateName } from "./git/cli"; import { getGitExtension } from "./gitExtension"; function _validateFoundRepos(git: API) { @@ -84,10 +83,6 @@ async function _autofill(uri?: string) { } else { _handleRepo(git); } - - const templateName = await getCommitTemplateName() - console.debug(templateName) - } /** From 6d9c8a9d7708f410edaec27a6c383a8b2f1e9f23 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:26:59 +0200 Subject: [PATCH 04/19] update reset_sandbox.sh --- bin/reset_sandbox.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/reset_sandbox.sh b/bin/reset_sandbox.sh index a81e3ced..f8cdeeb3 100755 --- a/bin/reset_sandbox.sh +++ b/bin/reset_sandbox.sh @@ -31,3 +31,7 @@ mkdir -p my_subdir mv bazz.js my_subdir # Delete. rm buzz.js + +# Commit template. +git config commit.template _COMMIT_MESSAGE +echo 'My commit prefix' >_COMMIT_MESSAGE From 5cddf0b5d1e3e2a53c720c68b70a75cf83182d23 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:27:23 +0200 Subject: [PATCH 05/19] feat: create commitTemplate.ts --- src/git/commitTemplate.ts | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/git/commitTemplate.ts diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts new file mode 100644 index 00000000..83401a96 --- /dev/null +++ b/src/git/commitTemplate.ts @@ -0,0 +1,98 @@ +/** + * Commit template module. + * + * TODO: Move to docs and link there. + * + * Read the message from the a configured commit template file and use it as a prefix in the message. + * + * A commit template is built-in Git behavior to see a value for the start of each commit message. This is useful if you have a ticket number, project name, or similar to add at the start of each commit. + * + * Note that VS Code and Git CLI both automatically read from this file when generating a commit. However, the value is hard to use. There is behavior in this extension to move the old message to the end and enter a commit type prefix and commit message before it, but there is no way to know from the content of the message for sure whether the old message is a commit template value or just a hand-typed message. + * + * To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git. + */ +import * as fs from 'fs'; +import * as path from 'path'; +import { getWorkspaceFolder } from "../workspace"; +import { execute } from "./cli"; + +const CONFIG_SUBCOMMAND = "config" +const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template' + +/** + * Get a value from the Git config. + * + * The CLI will assume local (project) project by default. + */ +export async function _getConfigValue(options: string[]) { + const workspace = getWorkspaceFolder() + const { stdout, stderr } = await execute( + workspace, + CONFIG_SUBCOMMAND, + options + ); + + if (stderr) { + console.debug(`stderr for 'git ${CONFIG_SUBCOMMAND}' command:`, stderr); + } + + return stdout +} + +/** + * Get commit template path. + * + * Get the configured value for a commit template path if set. + */ +async function _getCommitTemplatePath() { + try { + const options = [COMMIT_TEMPLATE_IDENTIFIER] + return await _getConfigValue(options) + } catch (_e) { + return null + } +} + +/** + * Read a file. + * + * NB. Use current workspace as the base path. + */ +function _readFile(filePath: string) { + const workspace = getWorkspaceFolder() + const p = path.join(workspace, filePath) + + let value + + try { + value = fs.readFileSync(p, "utf-8") + } catch (err) { + console.error(`Could not find template file: ${p}. ${err.toString()}`) + + return null + } + + if (!value) { + return null + } + + console.debug(`Read ${p} and found: ${value}`) + + return value +} + +/** + * Get value of commit template file. + * + * Return null if file is not configured or file is missing, without aborting. + */ +export async function getCommitTemplateValue() { + const filePath = await _getCommitTemplatePath() + + if (!filePath) { + console.error(`Could not read missing file: ${filePath}`) + return null + } + + return _readFile(filePath) +} From 7cc7953c71e19c8d0c397062fbbaf9941dcf3fde Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:28:44 +0200 Subject: [PATCH 06/19] update cli.ts --- src/git/cli.ts | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/src/git/cli.ts b/src/git/cli.ts index c101c075..bb5ade15 100644 --- a/src/git/cli.ts +++ b/src/git/cli.ts @@ -13,7 +13,7 @@ const exec = util.promisify(childProcess.exec); /** * Run a `git` subcommand with options and return output. */ -function _execute(cwd: string, subcommand: string, options: string[] = []) { +export function execute(cwd: string, subcommand: string, options: string[] = []) { const command = `git ${subcommand} ${options.join(" ")}`; const result = exec(command, { cwd }); @@ -44,8 +44,10 @@ async function _diffIndex(options: string[] = []): Promise> { ...options, "HEAD", ]; - const { stdout, stderr } = await _execute( - getWorkspaceFolder(), + + const workspace = getWorkspaceFolder() + const { stdout, stderr } = await execute( + workspace, cmd, fullOptions ); @@ -88,36 +90,3 @@ export async function getChanges() { } return allChanges; } - - -/** - * Get a value from the Git config. - * - * The CLI will assume local (project) project by default. - */ -export async function _getConfigValue(options: string[]) { - const cmd = "config" - - const { stdout, stderr } = await _execute( - getWorkspaceFolder(), - cmd, - options - ); - - if (stderr) { - console.debug(`stderr for 'git ${cmd}' command:`, stderr); - } - - return stdout -} - -/** - * Get the configured value for a commit template path if set, or empty string. - */ -export async function getCommitTemplateName() { - try { - return await _getConfigValue(['commit.template']) - } catch (_e) { - return "" - } -} From 7f3bc8330781f4741feacb8873c8c1c44302e54e Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:28:51 +0200 Subject: [PATCH 07/19] update autofill.ts --- src/autofill.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/autofill.ts b/src/autofill.ts index 9fd508ea..9ae6cbe2 100644 --- a/src/autofill.ts +++ b/src/autofill.ts @@ -4,6 +4,7 @@ import * as vscode from "vscode"; import { Repository } from "./api/git"; import { getChanges } from "./git/cli"; +import { getCommitTemplateValue } from "./git/commitTemplate"; import { getCommitMsg, setCommitMsg } from "./gitExtension"; import { generateMsg } from "./prepareCommitMsg"; @@ -39,5 +40,8 @@ export async function makeAndFillCommitMsg(repository: Repository) { const newMsg = generateMsg(fileChanges, oldMsg); console.debug("New message: ", newMsg); + const commitMessageValue = await getCommitTemplateValue() + console.debug({ commitMessageValue }) + setCommitMsg(repository, newMsg); } From 31d99ac0eb90e9803dd867a80ad8111b61d92bf3 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:31:25 +0200 Subject: [PATCH 08/19] style: format --- src/autofill.ts | 4 ++-- src/git/cli.ts | 14 ++++++------- src/git/commitTemplate.ts | 44 +++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/autofill.ts b/src/autofill.ts index 9ae6cbe2..d3c01a19 100644 --- a/src/autofill.ts +++ b/src/autofill.ts @@ -40,8 +40,8 @@ export async function makeAndFillCommitMsg(repository: Repository) { const newMsg = generateMsg(fileChanges, oldMsg); console.debug("New message: ", newMsg); - const commitMessageValue = await getCommitTemplateValue() - console.debug({ commitMessageValue }) + const commitMessageValue = await getCommitTemplateValue(); + console.debug({ commitMessageValue }); setCommitMsg(repository, newMsg); } diff --git a/src/git/cli.ts b/src/git/cli.ts index bb5ade15..eed2c64e 100644 --- a/src/git/cli.ts +++ b/src/git/cli.ts @@ -13,7 +13,11 @@ const exec = util.promisify(childProcess.exec); /** * Run a `git` subcommand with options and return output. */ -export function execute(cwd: string, subcommand: string, options: string[] = []) { +export function execute( + cwd: string, + subcommand: string, + options: string[] = [] +) { const command = `git ${subcommand} ${options.join(" ")}`; const result = exec(command, { cwd }); @@ -45,12 +49,8 @@ async function _diffIndex(options: string[] = []): Promise> { "HEAD", ]; - const workspace = getWorkspaceFolder() - const { stdout, stderr } = await execute( - workspace, - cmd, - fullOptions - ); + const workspace = getWorkspaceFolder(); + const { stdout, stderr } = await execute(workspace, cmd, fullOptions); if (stderr) { console.debug(`stderr for 'git ${cmd}' command:`, stderr); diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index 83401a96..c1456b13 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -11,13 +11,13 @@ * * To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git. */ -import * as fs from 'fs'; -import * as path from 'path'; +import * as fs from "fs"; +import * as path from "path"; import { getWorkspaceFolder } from "../workspace"; import { execute } from "./cli"; -const CONFIG_SUBCOMMAND = "config" -const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template' +const CONFIG_SUBCOMMAND = "config"; +const COMMIT_TEMPLATE_IDENTIFIER = "commit.template"; /** * Get a value from the Git config. @@ -25,7 +25,7 @@ const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template' * The CLI will assume local (project) project by default. */ export async function _getConfigValue(options: string[]) { - const workspace = getWorkspaceFolder() + const workspace = getWorkspaceFolder(); const { stdout, stderr } = await execute( workspace, CONFIG_SUBCOMMAND, @@ -36,7 +36,7 @@ export async function _getConfigValue(options: string[]) { console.debug(`stderr for 'git ${CONFIG_SUBCOMMAND}' command:`, stderr); } - return stdout + return stdout; } /** @@ -46,10 +46,10 @@ export async function _getConfigValue(options: string[]) { */ async function _getCommitTemplatePath() { try { - const options = [COMMIT_TEMPLATE_IDENTIFIER] - return await _getConfigValue(options) + const options = [COMMIT_TEMPLATE_IDENTIFIER]; + return await _getConfigValue(options); } catch (_e) { - return null + return null; } } @@ -59,26 +59,26 @@ async function _getCommitTemplatePath() { * NB. Use current workspace as the base path. */ function _readFile(filePath: string) { - const workspace = getWorkspaceFolder() - const p = path.join(workspace, filePath) + const workspace = getWorkspaceFolder(); + const p = path.join(workspace, filePath); - let value + let value; try { - value = fs.readFileSync(p, "utf-8") + value = fs.readFileSync(p, "utf-8"); } catch (err) { - console.error(`Could not find template file: ${p}. ${err.toString()}`) + console.error(`Could not find template file: ${p}. ${err.toString()}`); - return null + return null; } if (!value) { - return null + return null; } - console.debug(`Read ${p} and found: ${value}`) + console.debug(`Read ${p} and found: ${value}`); - return value + return value; } /** @@ -87,12 +87,12 @@ function _readFile(filePath: string) { * Return null if file is not configured or file is missing, without aborting. */ export async function getCommitTemplateValue() { - const filePath = await _getCommitTemplatePath() + const filePath = await _getCommitTemplatePath(); if (!filePath) { - console.error(`Could not read missing file: ${filePath}`) - return null + console.error(`Could not read missing file: ${filePath}`); + return null; } - return _readFile(filePath) + return _readFile(filePath); } From eae7440ceb3ce60ddaf9baf6053a09f9f8d4b6cb Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:11:52 +0200 Subject: [PATCH 09/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index c1456b13..29961138 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -3,13 +3,23 @@ * * TODO: Move to docs and link there. * - * Read the message from the a configured commit template file and use it as a prefix in the message. + * Read the message from the a configured commit template file and use it as a + * prefix in the message. * - * A commit template is built-in Git behavior to see a value for the start of each commit message. This is useful if you have a ticket number, project name, or similar to add at the start of each commit. + * A commit template is built-in Git behavior to see a value for the start of + * each commit message. This is useful if you have a ticket number, project + * name, or similar to add at the start of each commit. * - * Note that VS Code and Git CLI both automatically read from this file when generating a commit. However, the value is hard to use. There is behavior in this extension to move the old message to the end and enter a commit type prefix and commit message before it, but there is no way to know from the content of the message for sure whether the old message is a commit template value or just a hand-typed message. + * Note that VS Code and Git CLI both automatically read from this file when + * generating a commit. However, the value is hard to use. There is behavior in + * this extension to move the old message to the end and enter a commit type + * prefix and commit message before it, but there is no way to know from the + * content of the message for sure whether the old message is a commit template + * value or just a hand-typed message. * - * To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git. + * To avoid making an extra config value for the extension that one has to + * manage say in a Settings file or internal data, the approach is rather to use + * the existing commit template pattern in Git. */ import * as fs from "fs"; import * as path from "path"; From 47ca759b1c26ed1698233699ee8cb2e5d7376a61 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:04:41 +0200 Subject: [PATCH 10/19] chore: pull in changes from main in extension.ts --- src/extension.ts | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 695fea49..7ec283ca 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -57,34 +57,9 @@ async function _handleRepos(git: API, sourceControl: any) { */ async function _handleRepo(git: API) { const targetRepo = git.repositories[0]; - await makeAndFillCommitMsg(targetRepo); } -async function _autofill(uri?: string) { - const git = getGitExtension(); - - if (!git) { - vscode.window.showErrorMessage("Unable to load Git Extension"); - return; - } - - if (git.repositories.length === 0) { - vscode.window.showErrorMessage( - "No repos found. Please open a repo or run git init then try this extension again." - ); - return; - } - - vscode.commands.executeCommand("workbench.view.scm"); - - if (uri) { - _handleRepos(git, uri); - } else { - _handleRepo(git); - } -} - /** * Choose the relevant repo and apply autofill logic on files there. */ From 7d77e14958a53b42e448ab9162a7b785c3d8281a Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:07:48 +0200 Subject: [PATCH 11/19] fix: update commitTemplate.ts --- src/git/commitTemplate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index 29961138..eeebba92 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -76,7 +76,7 @@ function _readFile(filePath: string) { try { value = fs.readFileSync(p, "utf-8"); - } catch (err) { + } catch (err: any) { console.error(`Could not find template file: ${p}. ${err.toString()}`); return null; From d7ee6c60b996436ef86cd5f34bf176c9b1dc93ec Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:12:22 +0200 Subject: [PATCH 12/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index eeebba92..a79e32c4 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -31,11 +31,10 @@ const COMMIT_TEMPLATE_IDENTIFIER = "commit.template"; /** * Get a value from the Git config. - * - * The CLI will assume local (project) project by default. */ export async function _getConfigValue(options: string[]) { const workspace = getWorkspaceFolder(); + const { stdout, stderr } = await execute( workspace, CONFIG_SUBCOMMAND, @@ -101,6 +100,7 @@ export async function getCommitTemplateValue() { if (!filePath) { console.error(`Could not read missing file: ${filePath}`); + return null; } From 23ffa5abb9cca0f4a163fb627605ba08767a158b Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:15:03 +0200 Subject: [PATCH 13/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index a79e32c4..a66c44df 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -65,7 +65,8 @@ async function _getCommitTemplatePath() { /** * Read a file. * - * NB. Use current workspace as the base path. + * @param filePath: Path to a file to read, relative to the workspace root. + * e.g. "abc.txt" or "abc/def.txt" */ function _readFile(filePath: string) { const workspace = getWorkspaceFolder(); @@ -85,7 +86,7 @@ function _readFile(filePath: string) { return null; } - console.debug(`Read ${p} and found: ${value}`); + console.debug(`Found file: ${p}. Found contents: ${value}`); return value; } From 84493a475ae6ded95e06030be4996b7850b5a09c Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:17:32 +0200 Subject: [PATCH 14/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index a66c44df..8c731205 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -65,7 +65,7 @@ async function _getCommitTemplatePath() { /** * Read a file. * - * @param filePath: Path to a file to read, relative to the workspace root. + * @param filePath Path to a file to read, relative to the workspace root. * e.g. "abc.txt" or "abc/def.txt" */ function _readFile(filePath: string) { @@ -94,7 +94,8 @@ function _readFile(filePath: string) { /** * Get value of commit template file. * - * Return null if file is not configured or file is missing, without aborting. + * @return Contents of a configured commit message template file, or `null` if + * file is not configured or file is missing. */ export async function getCommitTemplateValue() { const filePath = await _getCommitTemplatePath(); From 8100fa909db121b58734bf5fd4328b5bafa429f4 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:18:51 +0200 Subject: [PATCH 15/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index 8c731205..1608812d 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -30,7 +30,7 @@ const CONFIG_SUBCOMMAND = "config"; const COMMIT_TEMPLATE_IDENTIFIER = "commit.template"; /** - * Get a value from the Git config. + * Get a value from the local Git config. */ export async function _getConfigValue(options: string[]) { const workspace = getWorkspaceFolder(); @@ -56,8 +56,11 @@ export async function _getConfigValue(options: string[]) { async function _getCommitTemplatePath() { try { const options = [COMMIT_TEMPLATE_IDENTIFIER]; + return await _getConfigValue(options); } catch (_e) { + console.error(_e) + return null; } } From f273d94526c502587fd2e672ab34390e483a11e4 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:37:02 +0200 Subject: [PATCH 16/19] update cli.ts --- src/cli.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index c0dfec5f..3e3b7954 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,6 +18,11 @@ import { generateMsg } from "./prepareCommitMsg"; * * Expect multi-line text from `git diff-index` command as the first item in the shell arguments. * + * TODO: How to reverse the order so reading the value and using it as old message can appear _first_. + * Note that, unlike the VS Code extension, the CLI logic here cannot read an + * "old message" from the Git pane so that is not passed to `generateMsg`. + * Though maybe this can be modified using `commitTemplate.ts`. + * * Returns a suitable generated commit message as text. */ function main(args: string[]) { From 723b19238c12afce33a7d80e4f6f74f65d17af1d Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:37:09 +0200 Subject: [PATCH 17/19] update autofill.ts --- src/autofill.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/autofill.ts b/src/autofill.ts index d3c01a19..785ca8ce 100644 --- a/src/autofill.ts +++ b/src/autofill.ts @@ -22,7 +22,11 @@ Try saving your files or stage any new (untracked) files.\ * 2. Generate a message. * 3. Push message value to the commit message box. * - * This is based on `prefixCommit` from the `git-prefix` extension. + * New functionality in the extension - the commit message file is read + * explicitly and the content used. Any content in the Git pane that was the + * "old message" is ignored then. + * + * This function is based on `prefixCommit` from the `git-prefix` extension. */ export async function makeAndFillCommitMsg(repository: Repository) { const fileChanges = await getChanges(); From 121da71b12748ff6e7934ecc17bd5578a744b4d6 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:37:13 +0200 Subject: [PATCH 18/19] update prepareCommitMsg.ts --- src/prepareCommitMsg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prepareCommitMsg.ts b/src/prepareCommitMsg.ts index 2e0a9dbf..a3de2eab 100644 --- a/src/prepareCommitMsg.ts +++ b/src/prepareCommitMsg.ts @@ -218,7 +218,7 @@ export function _generateMsgWithOld(lines: string[], oldMsg: string) { * * Old message could be the current commit message value in the UI box (which might be a commit * message template that VS Code has filled in), or a commit message template read from a file in - * the case of a hook flow without VS Code. + * the case of a hook flow without VS Code (built-in Git functionality). * * @param lines A list of text values describing how files changes. */ From d55d60f785a6e400a57237dd315ed40f9ed92f2a Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Sat, 16 Oct 2021 22:37:37 +0200 Subject: [PATCH 19/19] update commitTemplate.ts --- src/git/commitTemplate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/git/commitTemplate.ts b/src/git/commitTemplate.ts index 1608812d..0be5556b 100644 --- a/src/git/commitTemplate.ts +++ b/src/git/commitTemplate.ts @@ -59,7 +59,7 @@ async function _getCommitTemplatePath() { return await _getConfigValue(options); } catch (_e) { - console.error(_e) + console.error(_e); return null; }