Skip to content

Commit 34af748

Browse files
committed
Fixes #598 - apply changes not working for 2 refs
1 parent 4b0e724 commit 34af748

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
9+
### Fixed
10+
11+
- Fixes [#598](https://github.com/eamodio/vscode-gitlens/issues/598) — Apply changes when comparing a file from two branches is not working
12+
713
## [9.2.1] - 2018-12-16
814

915
### Changed

src/git/gitService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,18 @@ export class GitService implements Disposable {
443443
}
444444

445445
@log()
446-
async applyChangesToWorkingFile(uri: GitUri, ref?: string) {
447-
ref = ref || uri.sha;
448-
if (ref === undefined || uri.repoPath === undefined) return;
446+
async applyChangesToWorkingFile(uri: GitUri, ref1?: string, ref2?: string) {
447+
ref1 = ref1 || uri.sha;
448+
if (ref1 === undefined || uri.repoPath === undefined) return;
449+
450+
if (ref2 === undefined) {
451+
ref2 = ref1;
452+
ref1 = `${ref1}^`;
453+
}
449454

450455
let patch;
451456
try {
452-
patch = await Git.diff(uri.repoPath, uri.fsPath, `${ref}^`, ref);
457+
patch = await Git.diff(uri.repoPath, uri.fsPath, ref1, ref2);
453458
void (await Git.apply(uri.repoPath!, patch));
454459
}
455460
catch (ex) {

src/views/viewCommands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ export class ViewCommands implements Disposable {
163163

164164
void (await this.openFile(node));
165165

166+
if (node instanceof ResultsFileNode) {
167+
void (await Container.git.applyChangesToWorkingFile(node.uri, node.ref1, node.ref2));
168+
169+
return;
170+
}
171+
166172
if (node.uri.sha !== undefined && node.uri.sha !== 'HEAD') {
167173
void (await Container.git.applyChangesToWorkingFile(node.uri));
168174
}

0 commit comments

Comments
 (0)