From 39a6babf250bf4dd7c89e55977e32cf92a9ea4af Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 11 Jul 2024 14:40:33 -0700 Subject: [PATCH 1/4] fix: print error message and exit when git pull fails --- apps/sparo-lib/src/cli/commands/pull.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/sparo-lib/src/cli/commands/pull.ts b/apps/sparo-lib/src/cli/commands/pull.ts index 3e2cc417..39aa511a 100644 --- a/apps/sparo-lib/src/cli/commands/pull.ts +++ b/apps/sparo-lib/src/cli/commands/pull.ts @@ -4,6 +4,7 @@ import { GitService } from '../../services/GitService'; import { GitRemoteFetchConfigService } from '../../services/GitRemoteFetchConfigService'; import { SparoProfileService } from '../../services/SparoProfileService'; +import type { SpawnSyncReturns } from 'child_process'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import type { ICommand } from './base'; import type { TerminalService } from '../../services/TerminalService'; @@ -69,7 +70,12 @@ export class PullCommand implements ICommand { await this._gitRemoteFetchConfigService.pruneRemoteBranchesInGitConfigAsync(remote || 'origin'); // invoke native git pull command - gitService.executeGitCommand({ args: pullArgs }); + const pullProcess: SpawnSyncReturns = gitService.executeGitCommand({ args: pullArgs }); + + if (pullProcess.status !== 0) { + // Pull failed + throw new Error('"git pull" operation failed'); + } // check whether profile exist in local branch if (!isNoProfile) { From 03e6bcb94a54109d6483af5205130b63731a19fe Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 11 Jul 2024 14:41:06 -0700 Subject: [PATCH 2/4] chore: rush change --- .../sparo/fix-failed-pull_2024-07-11-21-41.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/sparo/fix-failed-pull_2024-07-11-21-41.json diff --git a/common/changes/sparo/fix-failed-pull_2024-07-11-21-41.json b/common/changes/sparo/fix-failed-pull_2024-07-11-21-41.json new file mode 100644 index 00000000..768b0817 --- /dev/null +++ b/common/changes/sparo/fix-failed-pull_2024-07-11-21-41.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "Print error message and exit when git pull fails", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file From f5e91ca3f4228ac81b5e37822452848d84177395 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 11 Jul 2024 15:46:33 -0700 Subject: [PATCH 3/4] chore: print exit code in error message --- apps/sparo-lib/src/cli/commands/pull.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sparo-lib/src/cli/commands/pull.ts b/apps/sparo-lib/src/cli/commands/pull.ts index 39aa511a..2bc44d58 100644 --- a/apps/sparo-lib/src/cli/commands/pull.ts +++ b/apps/sparo-lib/src/cli/commands/pull.ts @@ -74,7 +74,7 @@ export class PullCommand implements ICommand { if (pullProcess.status !== 0) { // Pull failed - throw new Error('"git pull" operation failed'); + throw new Error(`"git pull" operation failed (exit code ${pullProcess.status})`); } // check whether profile exist in local branch From d27a941ae5000a25105f5d44498c400591093fac Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 11 Jul 2024 15:48:13 -0700 Subject: [PATCH 4/4] chore: sparo exit with the same code when git pull fails --- apps/sparo-lib/src/cli/commands/pull.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/sparo-lib/src/cli/commands/pull.ts b/apps/sparo-lib/src/cli/commands/pull.ts index 2bc44d58..13f21571 100644 --- a/apps/sparo-lib/src/cli/commands/pull.ts +++ b/apps/sparo-lib/src/cli/commands/pull.ts @@ -74,7 +74,8 @@ export class PullCommand implements ICommand { if (pullProcess.status !== 0) { // Pull failed - throw new Error(`"git pull" operation failed (exit code ${pullProcess.status})`); + process.exitCode = pullProcess.status || 1; + throw new Error(`"git pull" operation failed`); } // check whether profile exist in local branch