|
1 |
| -using System.Collections.Generic; |
2 |
| -using System.Text; |
| 1 | +using System.Text; |
3 | 2 |
|
4 | 3 | namespace SourceGit.Commands
|
5 | 4 | {
|
6 | 5 | public class Restore : Command
|
7 | 6 | {
|
8 | 7 | /// <summary>
|
9 |
| - /// Only used to discard all changes in the working directory and staged area. |
| 8 | + /// Only used for single staged change. |
10 | 9 | /// </summary>
|
11 | 10 | /// <param name="repo"></param>
|
12 |
| - public Restore(string repo) |
13 |
| - { |
14 |
| - WorkingDirectory = repo; |
15 |
| - Context = repo; |
16 |
| - Args = "restore --source=HEAD --staged --worktree --recurse-submodules ."; |
17 |
| - } |
18 |
| - |
19 |
| - /// <summary> |
20 |
| - /// Discard changes with git (< 2.25.0) that does not support the `--pathspec-from-file` option. |
21 |
| - /// </summary> |
22 |
| - /// <param name="repo"></param> |
23 |
| - /// <param name="files"></param> |
24 |
| - /// <param name="extra"></param> |
25 |
| - public Restore(string repo, List<string> files, string extra) |
| 11 | + /// <param name="stagedChange"></param> |
| 12 | + public Restore(string repo, Models.Change stagedChange) |
26 | 13 | {
|
27 | 14 | WorkingDirectory = repo;
|
28 | 15 | Context = repo;
|
29 | 16 |
|
30 | 17 | var builder = new StringBuilder();
|
31 |
| - builder.Append("restore "); |
32 |
| - if (!string.IsNullOrEmpty(extra)) |
33 |
| - builder.Append(extra).Append(" "); |
34 |
| - builder.Append("--"); |
35 |
| - foreach (var f in files) |
36 |
| - builder.Append(' ').Append('"').Append(f).Append('"'); |
| 18 | + builder.Append("restore --staged -- \""); |
| 19 | + builder.Append(stagedChange.Path); |
| 20 | + builder.Append('"'); |
| 21 | + |
| 22 | + if (stagedChange.Index == Models.ChangeState.Renamed) |
| 23 | + { |
| 24 | + builder.Append(" \""); |
| 25 | + builder.Append(stagedChange.OriginalPath); |
| 26 | + builder.Append('"'); |
| 27 | + } |
| 28 | + |
37 | 29 | Args = builder.ToString();
|
38 | 30 | }
|
39 | 31 |
|
40 | 32 | /// <summary>
|
41 |
| - /// Discard changes with git (>= 2.25.0) that supports the `--pathspec-from-file` option. |
| 33 | + /// Restore changes given in a path-spec file. |
42 | 34 | /// </summary>
|
43 | 35 | /// <param name="repo"></param>
|
44 | 36 | /// <param name="pathspecFile"></param>
|
45 |
| - /// <param name="extra"></param> |
46 |
| - public Restore(string repo, string pathspecFile, string extra) |
| 37 | + /// <param name="isStaged"></param> |
| 38 | + public Restore(string repo, string pathspecFile, bool isStaged) |
47 | 39 | {
|
48 | 40 | WorkingDirectory = repo;
|
49 | 41 | Context = repo;
|
50 | 42 |
|
51 | 43 | var builder = new StringBuilder();
|
52 | 44 | builder.Append("restore ");
|
53 |
| - if (!string.IsNullOrEmpty(extra)) |
54 |
| - builder.Append(extra).Append(" "); |
55 |
| - builder.Append("--pathspec-from-file=\"").Append(pathspecFile).Append('"'); |
| 45 | + builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules "); |
| 46 | + builder.Append("--pathspec-from-file=\""); |
| 47 | + builder.Append(pathspecFile); |
| 48 | + builder.Append('"'); |
| 49 | + |
56 | 50 | Args = builder.ToString();
|
57 | 51 | }
|
58 | 52 | }
|
|
0 commit comments