Skip to content

Commit ed88386

Browse files
Terminal Removes includeUntracked from getDiff and intentToAdd from stageFiles
Closes #4364 Closes #4365
1 parent 25919d1 commit ed88386

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

src/commands/patches.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,26 @@ abstract class CreatePatchCommandBase extends GlCommandBase {
167167
repo ??= await getRepositoryOrShowPicker(this.container, title);
168168
if (repo == null) return;
169169

170-
return repo.git.diff.getDiff?.(args?.to ?? uncommitted, args?.from ?? 'HEAD', {
171-
includeUntracked: args?.includeUntracked ?? (args?.to != null || args?.to === uncommitted),
172-
uris: args?.uris,
173-
});
170+
let untrackedPaths: string[] | undefined;
171+
try {
172+
if (args?.to === uncommitted) {
173+
const status = await repo.git.status?.getStatus();
174+
175+
untrackedPaths = status?.untrackedChanges.map(f => f.path);
176+
177+
if (untrackedPaths?.length) {
178+
await repo.git.staging?.stageFiles(untrackedPaths);
179+
}
180+
}
181+
182+
return await repo.git.diff.getDiff?.(args?.to ?? uncommitted, args?.from ?? 'HEAD', {
183+
uris: args?.uris,
184+
});
185+
} finally {
186+
if (untrackedPaths?.length) {
187+
await repo.git.staging?.unstageFiles(untrackedPaths);
188+
}
189+
}
174190
}
175191

176192
abstract override execute(args?: CreatePatchCommandArgs): Promise<void>;

src/env/node/git/sub-providers/diff.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class DiffGitSubProvider implements GitDiffSubProvider {
9494
repoPath: string,
9595
to: string,
9696
from?: string,
97-
options?: { context?: number; includeUntracked?: boolean; notation?: GitRevisionRangeNotation; uris?: Uri[] },
97+
options?: { context?: number; notation?: GitRevisionRangeNotation; uris?: Uri[] },
9898
): Promise<GitDiff | undefined> {
9999
const scope = getLogScope();
100100
const args = [`-U${options?.context ?? 3}`];
@@ -118,22 +118,6 @@ export class DiffGitSubProvider implements GitDiffSubProvider {
118118
args.push('--', ...paths);
119119
}
120120

121-
if (options?.includeUntracked && to === uncommitted) {
122-
const status = await this.provider.status?.getStatus(repoPath);
123-
124-
untrackedPaths = status?.untrackedChanges.map(f => f.path);
125-
126-
if (untrackedPaths?.length) {
127-
if (paths?.size) {
128-
untrackedPaths = untrackedPaths.filter(p => paths.has(p));
129-
}
130-
131-
if (untrackedPaths.length) {
132-
await this.provider.staging?.stageFiles(repoPath, untrackedPaths, { intentToAdd: true });
133-
}
134-
}
135-
}
136-
137121
let result;
138122
try {
139123
result = await this.git.exec(

src/env/node/git/sub-providers/staging.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,33 @@ export class StagingGitSubProvider implements GitStagingSubProvider {
6767
}
6868

6969
@log()
70-
async stageFile(repoPath: string, pathOrUri: string | Uri, options?: { intentToAdd?: boolean }): Promise<void> {
70+
async stageFile(repoPath: string, pathOrUri: string | Uri): Promise<void> {
7171
await this.git.exec(
7272
{ cwd: repoPath },
7373
'add',
74-
options?.intentToAdd ? '-N' : '-A',
74+
'-A',
7575
'--',
7676
typeof pathOrUri === 'string' ? pathOrUri : splitPath(pathOrUri, repoPath)[0],
7777
);
7878
}
7979

8080
@log()
81-
async stageFiles(
82-
repoPath: string,
83-
pathOrUri: string[] | Uri[],
84-
options?: { intentToAdd?: boolean },
85-
): Promise<void> {
81+
async stageFiles(repoPath: string, pathOrUri: string[] | Uri[]): Promise<void> {
8682
await this.git.exec(
8783
{ cwd: repoPath },
8884
'add',
89-
options?.intentToAdd ? '-N' : '-A',
85+
'-A',
9086
'--',
9187
...pathOrUri.map(p => (typeof p === 'string' ? p : splitPath(p, repoPath)[0])),
9288
);
9389
}
9490

9591
@log()
96-
async stageDirectory(
97-
repoPath: string,
98-
directoryOrUri: string | Uri,
99-
options?: { intentToAdd?: boolean },
100-
): Promise<void> {
92+
async stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<void> {
10193
await this.git.exec(
10294
{ cwd: repoPath },
10395
'add',
104-
options?.intentToAdd ? '-N' : '-A',
96+
'-A',
10597
'--',
10698
typeof directoryOrUri === 'string' ? directoryOrUri : splitPath(directoryOrUri, repoPath)[0],
10799
);

src/git/gitProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export interface GitDiffSubProvider {
447447
repoPath: string,
448448
to: string,
449449
from?: string,
450-
options?: { context?: number; includeUntracked?: boolean; notation?: GitRevisionRangeNotation; uris?: Uri[] },
450+
options?: { context?: number; notation?: GitRevisionRangeNotation; uris?: Uri[] },
451451
cancellation?: CancellationToken,
452452
): Promise<GitDiff | undefined>;
453453
getDiffFiles?(
@@ -652,9 +652,9 @@ export interface DisposableTemporaryGitIndex extends UnifiedAsyncDisposable {
652652

653653
export interface GitStagingSubProvider {
654654
createTemporaryIndex(repoPath: string, base: string): Promise<DisposableTemporaryGitIndex>;
655-
stageFile(repoPath: string, pathOrUri: string | Uri, options?: { intentToAdd?: boolean }): Promise<void>;
656-
stageFiles(repoPath: string, pathOrUri: string[] | Uri[], options?: { intentToAdd?: boolean }): Promise<void>;
657-
stageDirectory(repoPath: string, directoryOrUri: string | Uri, options?: { intentToAdd?: boolean }): Promise<void>;
655+
stageFile(repoPath: string, pathOrUri: string | Uri): Promise<void>;
656+
stageFiles(repoPath: string, pathOrUri: string[] | Uri[]): Promise<void>;
657+
stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<void>;
658658
unstageFile(repoPath: string, pathOrUri: string | Uri): Promise<void>;
659659
unstageFiles(repoPath: string, pathOrUri: string[] | Uri[]): Promise<void>;
660660
unstageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<void>;

0 commit comments

Comments
 (0)