mirror of
https://github.com/Microsoft/vscode
synced 2024-07-05 01:08:57 +00:00
Git - view stash should use the stash's parent commit for the left hand side (#203450)
This commit is contained in:
parent
b0d1f894c3
commit
adf93c270a
|
@ -3598,8 +3598,8 @@ export class CommandCenter {
|
|||
return;
|
||||
}
|
||||
|
||||
await result.repository.popStash(result.stash.index);
|
||||
await commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
await result.repository.popStash(result.stash.index);
|
||||
}
|
||||
|
||||
@command('git.stashApply', { repository: true })
|
||||
|
@ -3633,8 +3633,8 @@ export class CommandCenter {
|
|||
return;
|
||||
}
|
||||
|
||||
await result.repository.applyStash(result.stash.index);
|
||||
await commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
await result.repository.applyStash(result.stash.index);
|
||||
}
|
||||
|
||||
@command('git.stashDrop', { repository: true })
|
||||
|
@ -3709,6 +3709,7 @@ export class CommandCenter {
|
|||
}
|
||||
|
||||
const stashChanges = await repository.showStash(stash.index);
|
||||
const stashParentCommit = stash.parents.length > 0 ? stash.parents[0] : `${stash.hash}^`;
|
||||
|
||||
if (!stashChanges || stashChanges.length === 0) {
|
||||
return;
|
||||
|
@ -3720,13 +3721,13 @@ export class CommandCenter {
|
|||
const resources: { originalUri: Uri | undefined; modifiedUri: Uri | undefined }[] = [];
|
||||
for (const change of stashChanges) {
|
||||
if (change.status === Status.INDEX_ADDED) {
|
||||
resources.push({ originalUri: undefined, modifiedUri: toGitUri(change.uri, `stash@{${stash.index}}`) });
|
||||
resources.push({ originalUri: undefined, modifiedUri: toGitUri(change.uri, stash.hash) });
|
||||
} else if (change.status === Status.DELETED) {
|
||||
resources.push({ originalUri: change.uri, modifiedUri: undefined });
|
||||
resources.push({ originalUri: toGitUri(change.uri, stashParentCommit), modifiedUri: undefined });
|
||||
} else if (change.status === Status.INDEX_RENAMED) {
|
||||
resources.push({ originalUri: change.originalUri, modifiedUri: toGitUri(change.uri, `stash@{${stash.index}}`) });
|
||||
resources.push({ originalUri: toGitUri(change.originalUri, stashParentCommit), modifiedUri: toGitUri(change.uri, stash.hash) });
|
||||
} else {
|
||||
resources.push({ originalUri: change.uri, modifiedUri: toGitUri(change.uri, `stash@{${stash.index}}`) });
|
||||
resources.push({ originalUri: toGitUri(change.uri, stashParentCommit), modifiedUri: toGitUri(change.uri, stash.hash) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,11 @@ export interface IFileStatus {
|
|||
}
|
||||
|
||||
export interface Stash {
|
||||
index: number;
|
||||
description: string;
|
||||
branchName?: string;
|
||||
readonly hash: string;
|
||||
readonly parents: string[];
|
||||
readonly index: number;
|
||||
readonly description: string;
|
||||
readonly branchName?: string;
|
||||
}
|
||||
|
||||
interface MutableRemote extends Remote {
|
||||
|
@ -353,6 +355,7 @@ function sanitizePath(path: string): string {
|
|||
}
|
||||
|
||||
const COMMIT_FORMAT = '%H%n%aN%n%aE%n%at%n%ct%n%P%n%D%n%B';
|
||||
const STASH_FORMAT = '%H%n%P%n%gd%n%gs';
|
||||
|
||||
export interface ICloneOptions {
|
||||
readonly parentPath: string;
|
||||
|
@ -965,34 +968,28 @@ export function parseLsFiles(raw: string): LsFilesElement[] {
|
|||
.map(([, mode, object, stage, file]) => ({ mode, object, stage, file }));
|
||||
}
|
||||
|
||||
const stashRegex = /([0-9a-f]{40})\n(.*)\nstash@{(\d+)}\n(WIP\s)*on([^:]+):(.*)(?:\x00)/gmi;
|
||||
|
||||
function parseGitStashes(raw: string): Stash[] {
|
||||
const result: Stash[] = [];
|
||||
const regex = /^stash@{(\d+)}:(.+)$/;
|
||||
const descriptionRegex = /(WIP\s)*on([^:]+):(.*)$/i;
|
||||
|
||||
for (const stash of raw.split('\n').filter(s => !!s)) {
|
||||
// Extract index and description
|
||||
const match = regex.exec(stash);
|
||||
if (!match) {
|
||||
continue;
|
||||
let match, hash, parents, index, wip, branchName, description;
|
||||
|
||||
do {
|
||||
match = stashRegex.exec(raw);
|
||||
if (match === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
const [, index, description] = match;
|
||||
|
||||
// Extract branch name from description
|
||||
const descriptionMatch = descriptionRegex.exec(description);
|
||||
if (!descriptionMatch) {
|
||||
result.push({ index: parseInt(index), description: description.trim() });
|
||||
continue;
|
||||
}
|
||||
|
||||
const [, wip, branchName, message] = descriptionMatch;
|
||||
[, hash, parents, index, wip, branchName, description] = match;
|
||||
result.push({
|
||||
hash,
|
||||
parents: parents.split(' '),
|
||||
index: parseInt(index),
|
||||
description: wip ? `WIP (${message.trim()})` : message.trim(),
|
||||
branchName: branchName.trim()
|
||||
branchName: branchName.trim(),
|
||||
description: wip ? `WIP (${description.trim()})` : description.trim()
|
||||
});
|
||||
}
|
||||
} while (true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -2212,7 +2209,7 @@ export class Repository {
|
|||
}
|
||||
|
||||
async showStash(index: number): Promise<Change[] | undefined> {
|
||||
const args = ['stash', 'show', `stash@{${index}}`, '--name-status', '-z'];
|
||||
const args = ['stash', 'show', `stash@{${index}}`, '--name-status', '-z', '-u'];
|
||||
|
||||
try {
|
||||
const result = await this.exec(args);
|
||||
|
@ -2500,7 +2497,7 @@ export class Repository {
|
|||
}
|
||||
|
||||
async getStashes(): Promise<Stash[]> {
|
||||
const result = await this.exec(['stash', 'list']);
|
||||
const result = await this.exec(['stash', 'list', `--format=${STASH_FORMAT}`, '-z']);
|
||||
return parseGitStashes(result.stdout.trim());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user