Skip to content

Commit eb6a00e

Browse files
committed
Adds logging in error handling
1 parent f66a283 commit eb6a00e

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

src/commands/git/worktree.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
WorktreeDeleteError,
1515
WorktreeDeleteErrorReason,
1616
} from '../../git/errors';
17+
import type { GitDiff } from '../../git/models/diff';
1718
import type { GitBranchReference, GitReference } from '../../git/models/reference';
1819
import type { Repository } from '../../git/models/repository';
1920
import { uncommitted, uncommittedStaged } from '../../git/models/revision';
@@ -37,6 +38,7 @@ import { configuration } from '../../system/-webview/configuration';
3738
import { isDescendant } from '../../system/-webview/path';
3839
import { revealInFileExplorer } from '../../system/-webview/vscode';
3940
import { getWorkspaceFriendlyPath, openWorkspace } from '../../system/-webview/vscode/workspaces';
41+
import { Logger } from '../../system/logger';
4042
import { basename } from '../../system/path';
4143
import type { Deferred } from '../../system/promise';
4244
import { pluralize, truncateLeft } from '../../system/string';
@@ -1194,29 +1196,43 @@ export class WorktreeGitCommand extends QuickCommand<State> {
11941196
const sourceSvc = this.container.git.getRepositoryService(state.source?.uri ?? state.repo.uri);
11951197

11961198
if (!state.changes.contents || !state.changes.baseSha) {
1199+
let diff: GitDiff | undefined;
11971200
let untrackedPaths: string[] | undefined;
1198-
if (state.changes.type !== 'index') {
1199-
// stage any untracked files
1200-
const status = await sourceSvc.status.getStatus();
1201-
untrackedPaths = status?.untrackedChanges.map(f => f.path);
1201+
try {
1202+
if (state.changes.type !== 'index') {
1203+
// stage any untracked files to include them in the diff
1204+
const status = await sourceSvc.status.getStatus();
1205+
1206+
untrackedPaths = status?.untrackedChanges.map(f => f.path);
1207+
if (untrackedPaths?.length) {
1208+
try {
1209+
await sourceSvc.staging?.stageFiles(untrackedPaths);
1210+
} catch (ex) {
1211+
Logger.error(
1212+
ex,
1213+
`Failed to stage (${untrackedPaths.length}) untracked files for copying changes`,
1214+
);
1215+
}
1216+
}
1217+
}
1218+
1219+
diff = await sourceSvc.diff.getDiff?.(
1220+
state.changes.type === 'index' ? uncommittedStaged : uncommitted,
1221+
'HEAD',
1222+
);
1223+
} finally {
12021224
if (untrackedPaths?.length) {
12031225
try {
1204-
await sourceSvc.staging?.stageFiles(untrackedPaths);
1205-
} catch {}
1226+
await sourceSvc.staging?.unstageFiles(untrackedPaths);
1227+
} catch (ex) {
1228+
Logger.error(
1229+
ex,
1230+
`Failed to unstage (${untrackedPaths.length}) untracked files for copying changes`,
1231+
);
1232+
}
12061233
}
12071234
}
12081235

1209-
const diff = await sourceSvc.diff.getDiff?.(
1210-
state.changes.type === 'index' ? uncommittedStaged : uncommitted,
1211-
'HEAD',
1212-
);
1213-
1214-
if (untrackedPaths?.length) {
1215-
try {
1216-
await sourceSvc.staging?.unstageFiles(untrackedPaths);
1217-
} catch {}
1218-
}
1219-
12201236
if (!diff?.contents) {
12211237
void window.showErrorMessage(`No changes to copy`);
12221238

src/commands/patches.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
170170
let untrackedPaths: string[] | undefined;
171171
try {
172172
if (args?.to === uncommitted) {
173+
// stage any untracked files to include them in the diff
173174
const status = await repo.git.status?.getStatus();
174175

175176
untrackedPaths = status?.untrackedChanges.map(f => f.path);
176-
177177
if (untrackedPaths?.length) {
178-
await repo.git.staging?.stageFiles(untrackedPaths);
178+
try {
179+
await repo.git.staging?.stageFiles(untrackedPaths);
180+
} catch (ex) {
181+
Logger.error(ex, `Failed to stage (${untrackedPaths.length}) untracked files for patch`);
182+
}
179183
}
180184
}
181185

@@ -184,7 +188,11 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
184188
});
185189
} finally {
186190
if (untrackedPaths?.length) {
187-
await repo.git.staging?.unstageFiles(untrackedPaths);
191+
try {
192+
await repo.git.staging?.unstageFiles(untrackedPaths);
193+
} catch (ex) {
194+
Logger.error(ex, `Failed to unstage (${untrackedPaths.length}) untracked files for patch`);
195+
}
188196
}
189197
}
190198
}

0 commit comments

Comments
 (0)