Skip to content

Commit 6e501b1

Browse files
committed
feature!: now SourceGit requires git >= 2.25.1
Signed-off-by: leo <[email protected]>
1 parent 7b05b01 commit 6e501b1

21 files changed

+97
-139
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can find the current translation status in [TRANSLATION.md](https://github.c
5454

5555
## How to Use
5656

57-
**To use this tool, you need to install Git(>=2.23.0) first.**
57+
**To use this tool, you need to install Git(>=2.25.1) first.**
5858

5959
You can download the latest stable from [Releases](https://github.com/sourcegit-scm/sourcegit/releases/latest) or download workflow artifacts from [Github Actions](https://github.com/sourcegit-scm/sourcegit/actions) to try this app based on latest commits.
6060

src/Commands/Add.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.Text;
3-
4-
namespace SourceGit.Commands
1+
namespace SourceGit.Commands
52
{
63
public class Add : Command
74
{
@@ -12,20 +9,11 @@ public Add(string repo, bool includeUntracked)
129
Args = includeUntracked ? "add ." : "add -u .";
1310
}
1411

15-
public Add(string repo, List<string> changes)
12+
public Add(string repo, Models.Change change)
1613
{
1714
WorkingDirectory = repo;
1815
Context = repo;
19-
20-
var builder = new StringBuilder();
21-
builder.Append("add --");
22-
foreach (var c in changes)
23-
{
24-
builder.Append(" \"");
25-
builder.Append(c);
26-
builder.Append("\"");
27-
}
28-
Args = builder.ToString();
16+
Args = $"add -- \"{change.Path}\"";
2917
}
3018

3119
public Add(string repo, string pathspecFromFile)

src/Commands/Discard.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ namespace SourceGit.Commands
88
{
99
public static class Discard
1010
{
11+
/// <summary>
12+
/// Discard all local changes (unstaged & staged)
13+
/// </summary>
14+
/// <param name="repo"></param>
15+
/// <param name="includeIgnored"></param>
16+
/// <param name="log"></param>
1117
public static void All(string repo, bool includeIgnored, Models.ICommandLog log)
1218
{
1319
var changes = new QueryLocalChanges(repo).Result();
@@ -37,10 +43,17 @@ public static void All(string repo, bool includeIgnored, Models.ICommandLog log)
3743
}
3844

3945
new Reset(repo, "HEAD", "--hard") { Log = log }.Exec();
46+
4047
if (includeIgnored)
4148
new Clean(repo) { Log = log }.Exec();
4249
}
4350

51+
/// <summary>
52+
/// Discard selected changes (only unstaged).
53+
/// </summary>
54+
/// <param name="repo"></param>
55+
/// <param name="changes"></param>
56+
/// <param name="log"></param>
4457
public static void Changes(string repo, List<Models.Change> changes, Models.ICommandLog log)
4558
{
4659
var restores = new List<string>();
@@ -71,20 +84,12 @@ public static void Changes(string repo, List<Models.Change> changes, Models.ICom
7184
});
7285
}
7386

74-
if (Native.OS.GitVersion >= Models.GitVersions.RESTORE_WITH_PATHSPECFILE)
75-
{
76-
var tmpFile = Path.GetTempFileName();
77-
File.WriteAllLines(tmpFile, restores);
78-
new Restore(repo, tmpFile, "--worktree --recurse-submodules") { Log = log }.Exec();
79-
File.Delete(tmpFile);
80-
}
81-
else
87+
if (restores.Count > 0)
8288
{
83-
for (int i = 0; i < restores.Count; i += 32)
84-
{
85-
var count = Math.Min(32, restores.Count - i);
86-
new Restore(repo, restores.GetRange(i, count), "--worktree --recurse-submodules") { Log = log }.Exec();
87-
}
89+
var pathSpecFile = Path.GetTempFileName();
90+
File.WriteAllLines(pathSpecFile, restores);
91+
new Restore(repo, pathSpecFile, false) { Log = log }.Exec();
92+
File.Delete(pathSpecFile);
8893
}
8994
}
9095
}

src/Commands/Restore.cs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,52 @@
1-
using System.Collections.Generic;
2-
using System.Text;
1+
using System.Text;
32

43
namespace SourceGit.Commands
54
{
65
public class Restore : Command
76
{
87
/// <summary>
9-
/// Only used to discard all changes in the working directory and staged area.
8+
/// Only used for single staged change.
109
/// </summary>
1110
/// <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 (&lt; 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)
2613
{
2714
WorkingDirectory = repo;
2815
Context = repo;
2916

3017
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+
3729
Args = builder.ToString();
3830
}
3931

4032
/// <summary>
41-
/// Discard changes with git (&gt;= 2.25.0) that supports the `--pathspec-from-file` option.
33+
/// Restore changes given in a path-spec file.
4234
/// </summary>
4335
/// <param name="repo"></param>
4436
/// <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)
4739
{
4840
WorkingDirectory = repo;
4941
Context = repo;
5042

5143
var builder = new StringBuilder();
5244
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+
5650
Args = builder.ToString();
5751
}
5852
}

src/Commands/Tag.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ public static bool Add(string repo, string name, string basedOn, string message,
2828
string tmp = Path.GetTempFileName();
2929
File.WriteAllText(tmp, message);
3030
cmd.Args += $"-F \"{tmp}\"";
31-
}
32-
else
33-
{
34-
cmd.Args += $"-m {name}";
31+
32+
var succ = cmd.Exec();
33+
File.Delete(tmp);
34+
return succ;
3535
}
3636

37+
cmd.Args += $"-m {name}";
3738
return cmd.Exec();
3839
}
3940

src/Models/GitVersions.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,16 @@ public static class GitVersions
55
/// <summary>
66
/// The minimal version of Git that required by this app.
77
/// </summary>
8-
public static readonly System.Version MINIMAL = new System.Version(2, 23, 0);
9-
10-
/// <summary>
11-
/// The minimal version of Git that supports the `add` command with the `--pathspec-from-file` option.
12-
/// </summary>
13-
public static readonly System.Version ADD_WITH_PATHSPECFILE = new System.Version(2, 25, 0);
14-
15-
/// <summary>
16-
/// The minimal version of Git that supports the `restore` command with the `--pathspec-from-file` option.
17-
/// </summary>
18-
public static readonly System.Version RESTORE_WITH_PATHSPECFILE = new System.Version(2, 25, 0);
8+
public static readonly System.Version MINIMAL = new(2, 25, 1);
199

2010
/// <summary>
2111
/// The minimal version of Git that supports the `stash push` command with the `--pathspec-from-file` option.
2212
/// </summary>
23-
public static readonly System.Version STASH_PUSH_WITH_PATHSPECFILE = new System.Version(2, 26, 0);
13+
public static readonly System.Version STASH_PUSH_WITH_PATHSPECFILE = new(2, 26, 0);
2414

2515
/// <summary>
2616
/// The minimal version of Git that supports the `stash push` command with the `--staged` option.
2717
/// </summary>
28-
public static readonly System.Version STASH_PUSH_ONLY_STAGED = new System.Version(2, 35, 0);
18+
public static readonly System.Version STASH_PUSH_ONLY_STAGED = new(2, 35, 0);
2919
}
3020
}

src/Resources/Locales/de_DE.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@
501501
<x:String x:Key="Text.Preferences.Git.Email.Placeholder" xml:space="preserve">Globale Git Benutzer Email</x:String>
502502
<x:String x:Key="Text.Preferences.Git.EnablePruneOnFetch" xml:space="preserve">Aktivere --prune beim fetchen</x:String>
503503
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">Aktiviere --ignore-cr-at-eol beim Unterschied</x:String>
504-
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Diese App setzt Git (&gt;= 2.23.0) voraus</x:String>
504+
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Diese App setzt Git (&gt;= 2.25.1) voraus</x:String>
505505
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Installationspfad</x:String>
506506
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Aktiviere HTTP SSL Verifizierung</x:String>
507507
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">Benutzername</x:String>

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@
511511
<x:String x:Key="Text.Preferences.Git.Email.Placeholder" xml:space="preserve">Global git user email</x:String>
512512
<x:String x:Key="Text.Preferences.Git.EnablePruneOnFetch" xml:space="preserve">Enable --prune on fetch</x:String>
513513
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">Enable --ignore-cr-at-eol in diff</x:String>
514-
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Git (&gt;= 2.23.0) is required by this app</x:String>
514+
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Git (&gt;= 2.25.1) is required by this app</x:String>
515515
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Install Path</x:String>
516516
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Enable HTTP SSL Verify</x:String>
517517
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">User Name</x:String>

src/Resources/Locales/es_ES.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@
515515
<x:String x:Key="Text.Preferences.Git.Email.Placeholder" xml:space="preserve">Email global del usuario git</x:String>
516516
<x:String x:Key="Text.Preferences.Git.EnablePruneOnFetch" xml:space="preserve">Habilitar --prune para fetch</x:String>
517517
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">Habilitar --ignore-cr-at-eol en diff</x:String>
518-
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Se requiere Git (&gt;= 2.23.0) para esta aplicación</x:String>
518+
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Se requiere Git (&gt;= 2.25.1) para esta aplicación</x:String>
519519
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Ruta de instalación</x:String>
520520
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Habilitar verificación HTTP SSL</x:String>
521521
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">Nombre de usuario</x:String>

src/Resources/Locales/fr_FR.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@
483483
<x:String x:Key="Text.Preferences.Git.Email" xml:space="preserve">E-mail utilsateur</x:String>
484484
<x:String x:Key="Text.Preferences.Git.Email.Placeholder" xml:space="preserve">E-mail utilsateur global</x:String>
485485
<x:String x:Key="Text.Preferences.Git.EnablePruneOnFetch" xml:space="preserve">Activer --prune pour fetch</x:String>
486-
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Cette application requière Git (&gt;= 2.23.0)</x:String>
486+
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Cette application requière Git (&gt;= 2.25.1)</x:String>
487487
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Chemin d'installation</x:String>
488488
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Activer la vérification HTTP SSL</x:String>
489489
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">Nom d'utilisateur</x:String>

0 commit comments

Comments
 (0)