Skip to content

Commit 64295a9

Browse files
committed
refactor: rewrite the way to checkout untracked/new-added file from stash
Signed-off-by: leo <[email protected]>
1 parent 8f647f8 commit 64295a9

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/ViewModels/StashesPage.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,16 @@ public void OpenChangeWithExternalDiffTool(Models.Change change)
198198

199199
public async Task CheckoutSingleFileAsync(Models.Change change)
200200
{
201-
var fullPath = Native.OS.GetAbsPath(_repo.FullPath, change.Path);
202-
var log = _repo.CreateLog($"Reset File to '{_selectedStash.SHA}'");
203-
204-
if (_untracked.Contains(change))
205-
{
206-
await Commands.SaveRevisionFile.RunAsync(_repo.FullPath, _selectedStash.Parents[2], change.Path, fullPath);
207-
}
208-
else if (change.Index == Models.ChangeState.Added)
209-
{
210-
await Commands.SaveRevisionFile.RunAsync(_repo.FullPath, _selectedStash.SHA, change.Path, fullPath);
211-
}
212-
else
213-
{
214-
await new Commands.Checkout(_repo.FullPath)
201+
var revision = _selectedStash.SHA;
202+
if (_untracked.Contains(change) && _selectedStash.Parents.Count == 3)
203+
revision = _selectedStash.Parents[2];
204+
else if (change.Index == Models.ChangeState.Added && _selectedStash.Parents.Count > 1)
205+
revision = _selectedStash.Parents[1];
206+
207+
var log = _repo.CreateLog($"Reset File to '{_selectedStash.Name}'");
208+
await new Commands.Checkout(_repo.FullPath)
215209
.Use(log)
216-
.FileWithRevisionAsync(change.Path, $"{_selectedStash.SHA}");
217-
}
218-
210+
.FileWithRevisionAsync(change.Path, revision);
219211
log.Complete();
220212
}
221213

0 commit comments

Comments
 (0)