Skip to content

Commit 589dc4b

Browse files
committed
feat: support multiple repos
1 parent a240816 commit 589dc4b

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/autofill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Try saving your files or stage any new (untracked) files.\
2424
* This is based on `prefixCommit` from the `git-prefix` extension.
2525
*/
2626
export async function makeAndFillCommitMsg(repository: Repository) {
27-
const fileChanges = await getChanges();
27+
const fileChanges = await getChanges(repository);
2828

2929
console.debug("diff-index:", fileChanges);
3030

src/git/cli.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
*/
66
import util = require("util");
77
import childProcess = require("child_process");
8-
8+
import { Repository } from "../api/git";
99
import { getWorkspaceFolder } from "../workspace";
10-
1110
const exec = util.promisify(childProcess.exec);
1211

1312
/**
14-
* Run a `git` subcommand with options and return output.
13+
* Run a `git` subcommand and return output.
1514
*/
1615
function _execute(cwd: string, subcommand: string, options: string[] = []) {
1716
const command = `git ${subcommand} ${options.join(" ")}`;
1817

19-
const result = exec(command, { cwd });
18+
console.debug(`Running command: ${command}, cwd: ${cwd}`);
2019

21-
return result;
20+
return exec(command, { cwd });
2221
}
2322

2423
/**
@@ -33,9 +32,12 @@ function _execute(cwd: string, subcommand: string, options: string[] = []) {
3332
* The output already seems to never have color info, from my testing, but the
3433
* no-color flagged is added still to be safe.
3534
*/
36-
async function _diffIndex(options: string[] = []): Promise<Array<string>> {
35+
async function _diffIndex(
36+
repository: Repository,
37+
options: string[] = []
38+
): Promise<Array<string>> {
39+
const cwd = repository.rootUri.path;
3740
const cmd = "diff-index";
38-
3941
const fullOptions = [
4042
"--name-status",
4143
"--find-renames",
@@ -44,11 +46,8 @@ async function _diffIndex(options: string[] = []): Promise<Array<string>> {
4446
...options,
4547
"HEAD",
4648
];
47-
const { stdout, stderr } = await _execute(
48-
getWorkspaceFolder(),
49-
cmd,
50-
fullOptions
51-
);
49+
50+
const { stdout, stderr } = await _execute(cwd, cmd, fullOptions);
5251

5352
if (stderr) {
5453
console.debug(`stderr for 'git ${cmd}' command:`, stderr);
@@ -68,8 +67,8 @@ async function _diffIndex(options: string[] = []): Promise<Array<string>> {
6867
*
6968
* Returns an array of strings.
7069
*/
71-
export async function getChanges() {
72-
const stagedChanges = await _diffIndex(["--cached"]);
70+
export async function getChanges(repository: Repository) {
71+
const stagedChanges = await _diffIndex(repository, ["--cached"]);
7372

7473
if (stagedChanges.length) {
7574
console.debug("Found staged changes");
@@ -81,7 +80,7 @@ export async function getChanges() {
8180
"Staging area is empty. Using unstaged files (tracked files only still)."
8281
);
8382

84-
const allChanges = await _diffIndex();
83+
const allChanges = await _diffIndex(repository);
8584

8685
if (!allChanges.length) {
8786
console.debug("No changes found");

0 commit comments

Comments
 (0)