Skip to content

Commit e30ed89

Browse files
committed
refactor: use git reset HEAD --pathspec-from-file=<pathspec> instead of git restore --staged --pathspec-from-file=<pathspec> to unstage files
Signed-off-by: leo <[email protected]>
1 parent 974c30b commit e30ed89

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/Commands/Discard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static async Task ChangesAsync(string repo, List<Models.Change> changes,
8686
{
8787
var pathSpecFile = Path.GetTempFileName();
8888
await File.WriteAllLinesAsync(pathSpecFile, restores).ConfigureAwait(false);
89-
await new Restore(repo, pathSpecFile, false).Use(log).ExecAsync().ConfigureAwait(false);
89+
await new Restore(repo, pathSpecFile).Use(log).ExecAsync().ConfigureAwait(false);
9090
File.Delete(pathSpecFile);
9191
}
9292
}

src/Commands/Reset.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@ public Reset(string repo, string revision, string mode)
88
Context = repo;
99
Args = $"reset {mode} {revision}";
1010
}
11+
12+
public Reset(string repo, string pathspec)
13+
{
14+
WorkingDirectory = repo;
15+
Context = repo;
16+
Args = $"reset HEAD --pathspec-from-file={pathspec.Quoted()}";
17+
}
1118
}
1219
}

src/Commands/Restore.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
using System.Text;
2-
3-
namespace SourceGit.Commands
1+
namespace SourceGit.Commands
42
{
53
public class Restore : Command
64
{
7-
public Restore(string repo, string pathspecFile, bool isStaged)
5+
public Restore(string repo, string pathspecFile)
86
{
97
WorkingDirectory = repo;
108
Context = repo;
11-
12-
var builder = new StringBuilder();
13-
builder.Append("restore --progress ");
14-
builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules ");
15-
builder.Append("--pathspec-from-file=").Append(pathspecFile.Quoted());
16-
17-
Args = builder.ToString();
9+
Args = $"restore --progress --worktree --recurse-submodules --pathspec-from-file={pathspecFile.Quoted()}";
1810
}
1911
}
2012
}

src/ViewModels/WorkingCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public async Task UnstageChangesAsync(List<Models.Change> changes, Models.Change
393393
}
394394
}
395395

396-
await new Commands.Restore(_repo.FullPath, pathSpecFile, true).Use(log).ExecAsync();
396+
await new Commands.Reset(_repo.FullPath, pathSpecFile).Use(log).ExecAsync();
397397
File.Delete(pathSpecFile);
398398
}
399399
log.Complete();

0 commit comments

Comments
 (0)