From d9618a627d0c1631dc9e36eedaa8e28756b0fc02 Mon Sep 17 00:00:00 2001 From: tnichols Date: Sun, 10 Apr 2022 23:31:10 +0800 Subject: [PATCH 1/4] fix recusrive submods --- src/simpleGit.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/simpleGit.ts b/src/simpleGit.ts index a6055b8c..a527ca8e 100644 --- a/src/simpleGit.ts +++ b/src/simpleGit.ts @@ -90,7 +90,36 @@ export class SimpleGit extends GitManager { async commitAll(message: string): Promise { if (this.plugin.settings.updateSubmodules) { this.plugin.setState(PluginState.commit); - await this.git.subModule(["foreach", "--recursive", `git add -A && if [ ! -z "$(git status --porcelain)" ]; then git commit -m "${await this.formatCommitMessage(message)}"; fi`], (err) => this.onError(err)); + this.git.outputHandler(async (x, y, z) => { + let body = "" + let root = this.app.vault.adapter.basePath + y.on('data', (chunk) => { + body += chunk.toString('utf8') + }) + y.on('end', async () => { + let m = body.split('\n') + let l = m.map(x => { + let a = x.match(/'([^']*)'/) + if (a != undefined) { + if (x.startsWith("Entering")) { + return root + "/" + a[1] + "/" + } + } + }) + + l.reverse() + l.forEach(async (x) => { + if (x != undefined) { + await this.git.cwd({path: x, root: false}).add("-A", (err) => this.onError(err)) + await this.git.cwd({path: x, root: false}).commit(await this.formatCommitMessage(message), (err) => this.onError(err)) + } + }) + }) + }) + + await this.git.subModule(["foreach", "--recursive", '']) + + this.git.outputHandler(() => {}) } this.plugin.setState(PluginState.add); From 13e6359a3f36a3091d73646e7c67cbbadea27879 Mon Sep 17 00:00:00 2001 From: tnichols Date: Mon, 11 Apr 2022 08:14:37 +0800 Subject: [PATCH 2/4] make changes --- src/simpleGit.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/simpleGit.ts b/src/simpleGit.ts index a527ca8e..2dabe1a9 100644 --- a/src/simpleGit.ts +++ b/src/simpleGit.ts @@ -92,7 +92,7 @@ export class SimpleGit extends GitManager { this.plugin.setState(PluginState.commit); this.git.outputHandler(async (x, y, z) => { let body = "" - let root = this.app.vault.adapter.basePath + let root = this.app.vault.adapter.basePath + (this.plugin.settings.basePath ? sep + this.plugin.settings.basePath : "") y.on('data', (chunk) => { body += chunk.toString('utf8') }) @@ -101,9 +101,7 @@ export class SimpleGit extends GitManager { let l = m.map(x => { let a = x.match(/'([^']*)'/) if (a != undefined) { - if (x.startsWith("Entering")) { - return root + "/" + a[1] + "/" - } + return root + sep + a[1] + sep } }) From 0f2e4d647ca850aa39a6323398c62248f72aa71c Mon Sep 17 00:00:00 2001 From: tnichols Date: Wed, 13 Apr 2022 23:14:12 +0800 Subject: [PATCH 3/4] fix var names --- src/simpleGit.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/simpleGit.ts b/src/simpleGit.ts index 2dabe1a9..02481e31 100644 --- a/src/simpleGit.ts +++ b/src/simpleGit.ts @@ -90,26 +90,26 @@ export class SimpleGit extends GitManager { async commitAll(message: string): Promise { if (this.plugin.settings.updateSubmodules) { this.plugin.setState(PluginState.commit); - this.git.outputHandler(async (x, y, z) => { + this.git.outputHandler(async (cmd, stdout, stderr) => { let body = "" let root = this.app.vault.adapter.basePath + (this.plugin.settings.basePath ? sep + this.plugin.settings.basePath : "") - y.on('data', (chunk) => { + stdout.on('data', (chunk) => { body += chunk.toString('utf8') }) - y.on('end', async () => { - let m = body.split('\n') - let l = m.map(x => { - let a = x.match(/'([^']*)'/) - if (a != undefined) { - return root + sep + a[1] + sep + stdout.on('end', async () => { + let submods = body.split('\n') + submods = submods.map(i => { + let submod = i.match(/'([^']*)'/) + if (submod != undefined) { + return root + sep + submod[1] + sep } }) - l.reverse() - l.forEach(async (x) => { - if (x != undefined) { - await this.git.cwd({path: x, root: false}).add("-A", (err) => this.onError(err)) - await this.git.cwd({path: x, root: false}).commit(await this.formatCommitMessage(message), (err) => this.onError(err)) + submods.reverse() + submods.forEach(async (i) => { + if (i != undefined) { + await this.git.cwd({path: i, root: false}).add("-A", (err) => this.onError(err)) + await this.git.cwd({path: i, root: false}).commit(await this.formatCommitMessage(message), (err) => this.onError(err)) } }) }) From 9005d4f65d39479d8712d5d2adbad06d644e8606 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Thu, 21 Apr 2022 00:38:07 +0200 Subject: [PATCH 4/4] fix: properly await recursive submodules --- src/simpleGit.ts | 63 +++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/simpleGit.ts b/src/simpleGit.ts index 02481e31..ba50f5fc 100644 --- a/src/simpleGit.ts +++ b/src/simpleGit.ts @@ -90,34 +90,47 @@ export class SimpleGit extends GitManager { async commitAll(message: string): Promise { if (this.plugin.settings.updateSubmodules) { this.plugin.setState(PluginState.commit); - this.git.outputHandler(async (cmd, stdout, stderr) => { - let body = "" - let root = this.app.vault.adapter.basePath + (this.plugin.settings.basePath ? sep + this.plugin.settings.basePath : "") - stdout.on('data', (chunk) => { - body += chunk.toString('utf8') - }) - stdout.on('end', async () => { - let submods = body.split('\n') - submods = submods.map(i => { - let submod = i.match(/'([^']*)'/) - if (submod != undefined) { - return root + sep + submod[1] + sep - } - }) - submods.reverse() - submods.forEach(async (i) => { - if (i != undefined) { - await this.git.cwd({path: i, root: false}).add("-A", (err) => this.onError(err)) - await this.git.cwd({path: i, root: false}).commit(await this.formatCommitMessage(message), (err) => this.onError(err)) + await new Promise(async (resolve, reject) => { + + this.git.outputHandler(async (cmd, stdout, stderr, args) => { + + // Do not run this handler on other commands + if (!(args.contains("submodule") && args.contains("foreach"))) return; + + let body = ""; + let root = (this.app.vault.adapter as FileSystemAdapter).getBasePath() + (this.plugin.settings.basePath ? sep + this.plugin.settings.basePath : ""); + stdout.on('data', (chunk) => { + body += chunk.toString('utf8'); + }); + stdout.on('end', async () => { + let submods = body.split('\n'); + + // Remove words like `Entering` in front of each line and filter empty lines + submods = submods.map(i => { + let submod = i.match(/'([^']*)'/); + if (submod != undefined) { + return root + sep + submod[1] + sep; + } + }); + + submods.reverse(); + for (const item of submods) { + // Catch empty lines + if (item != undefined) { + await this.git.cwd({ path: item, root: false }).add("-A", (err) => this.onError(err)); + await this.git.cwd({ path: item, root: false }).commit(await this.formatCommitMessage(message), (err) => this.onError(err)); + } } - }) - }) - }) - - await this.git.subModule(["foreach", "--recursive", '']) + resolve(); + }); + }); + + + await this.git.subModule(["foreach", "--recursive", '']); + this.git.outputHandler(() => { }); + }); - this.git.outputHandler(() => {}) } this.plugin.setState(PluginState.add);