Browse Source

Fixes #2033 untracked files in stashes

main
Eric Amodio 2 years ago
parent
commit
14d05f567b
4 changed files with 26 additions and 6 deletions
  1. +2
    -1
      CHANGELOG.md
  2. +2
    -1
      src/commands/diffWithPrevious.ts
  3. +14
    -3
      src/commands/gitCommands.actions.ts
  4. +8
    -1
      src/git/gitUri.ts

+ 2
- 1
CHANGELOG.md View File

@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## Fixed ## Fixed
- Fixes [#2033](https://github.com/gitkraken/vscode-gitlens/issues/2033) - Diffing, applying, and restoring untracked files in a stash doesn't work
- Fixes [#2028](https://github.com/gitkraken/vscode-gitlens/issues/2028) - Branch names with special characters '<' also causes errors on the command line &mdash; thanks to [PR #2030](https://github.com/gitkraken/vscode-gitlens/pull/2030) by mcy-kylin ([@mcy-kylin](https://github.com/mcy-kylin)) - Fixes [#2028](https://github.com/gitkraken/vscode-gitlens/issues/2028) - Branch names with special characters '<' also causes errors on the command line &mdash; thanks to [PR #2030](https://github.com/gitkraken/vscode-gitlens/pull/2030) by mcy-kylin ([@mcy-kylin](https://github.com/mcy-kylin))
- Fixes [#2028](https://github.com/gitkraken/vscode-gitlens/issues/2028) - Branch names with special characters like ';$|>' causes errors on the command line (terminal executed git commands) - Fixes [#2028](https://github.com/gitkraken/vscode-gitlens/issues/2028) - Branch names with special characters like ';$|>' causes errors on the command line (terminal executed git commands)
- Fixes [#2021](https://github.com/gitkraken/vscode-gitlens/issues/2021) - GitLab remote provider uses legacy routes &mdash; thanks to [PR #2022](https://github.com/gitkraken/vscode-gitlens/pull/2022) by Brian Williams ([@Brcrwilliams](https://github.com/Brcrwilliams)) - Fixes [#2021](https://github.com/gitkraken/vscode-gitlens/issues/2021) - GitLab remote provider uses legacy routes &mdash; thanks to [PR #2022](https://github.com/gitkraken/vscode-gitlens/pull/2022) by Brian Williams ([@Brcrwilliams](https://github.com/Brcrwilliams))
@ -4211,7 +4212,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Initial release but still heavily a work in progress. - Initial release but still heavily a work in progress.
[Unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.7...HEAD
[unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.7...HEAD
[12.0.6]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.6...gitkraken:v12.0.7 [12.0.6]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.6...gitkraken:v12.0.7
[12.0.6]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.5...gitkraken:v12.0.6 [12.0.6]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.5...gitkraken:v12.0.6
[12.0.5]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.4...gitkraken:v12.0.5 [12.0.5]: https://github.com/gitkraken/vscode-gitlens/compare/v12.0.4...gitkraken:v12.0.5

+ 2
- 1
src/commands/diffWithPrevious.ts View File

@ -56,7 +56,8 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
uri: args.commit.file.originalUri ?? args.commit.file.uri, uri: args.commit.file.originalUri ?? args.commit.file.uri,
}, },
rhs: { rhs: {
sha: args.commit.sha || '',
// If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file
sha: args.commit.file.status === '?' ? `${args.commit.sha}^3` : args.commit.sha || '',
uri: args.commit.file.uri, uri: args.commit.file.uri,
}, },
line: args.line, line: args.line,

+ 14
- 3
src/commands/gitCommands.actions.ts View File

@ -169,9 +169,16 @@ export namespace GitActions {
) { ) {
// Open the working file to ensure undo will work // Open the working file to ensure undo will work
void (await GitActions.Commit.openFile(file, ref1, { preserveFocus: true, preview: false })); void (await GitActions.Commit.openFile(file, ref1, { preserveFocus: true, preview: false }));
let ref = ref1.ref;
// If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file
if (typeof file !== 'string' && file.status === '?') {
ref = `${ref}^3`;
}
void (await Container.instance.git.applyChangesToWorkingFile( void (await Container.instance.git.applyChangesToWorkingFile(
GitUri.fromFile(file, ref1.repoPath, ref1.ref),
ref1.ref,
GitUri.fromFile(file, ref1.repoPath, ref),
ref,
ref2?.ref, ref2?.ref,
)); ));
} }
@ -502,7 +509,10 @@ export namespace GitActions {
options = refOrOptions as TextDocumentShowOptions; options = refOrOptions as TextDocumentShowOptions;
} else { } else {
const ref = refOrOptions as GitRevisionReference; const ref = refOrOptions as GitRevisionReference;
uri = GitUri.fromFile(fileOrUri, ref.repoPath, ref.ref); uri = GitUri.fromFile(fileOrUri, ref.repoPath, ref.ref);
// If the file is `?` (untracked), then this must be an untracked file in a stash, so just return
if (typeof fileOrUri !== 'string' && fileOrUri.status === '?') return;
} }
options = { preserveFocus: true, preview: false, ...options }; options = { preserveFocus: true, preview: false, ...options };
@ -663,7 +673,8 @@ export namespace GitActions {
ref = revision.ref; ref = revision.ref;
} else { } else {
path = file.path; path = file.path;
ref = file.status === 'D' ? `${revision.ref}^` : revision.ref;
ref =
file.status === `?` ? `${revision.ref}^3` : file.status === 'D' ? `${revision.ref}^` : revision.ref;
} }
void (await Container.instance.git.checkout(revision.repoPath, ref, { path: path })); void (await Container.instance.git.checkout(revision.repoPath, ref, { path: path }));

+ 8
- 1
src/git/gitUri.ts View File

@ -230,7 +230,14 @@ export class GitUri extends (Uri as any as UriEx) {
typeof file === 'string' ? file : (original && file.originalPath) || file.path, typeof file === 'string' ? file : (original && file.originalPath) || file.path,
repoPath, repoPath,
); );
return !ref ? new GitUri(uri, repoPath) : new GitUri(uri, { repoPath: repoPath, sha: ref });
return !ref
? new GitUri(uri, repoPath)
: new GitUri(uri, {
repoPath: repoPath,
// If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file
sha: typeof file !== 'string' && file.status === '?' ? `${ref}^3` : ref,
});
} }
static fromRepoPath(repoPath: string, ref?: string) { static fromRepoPath(repoPath: string, ref?: string) {

Loading…
Cancel
Save