Skip to content

Commit b7e0e38

Browse files
committed
feature: stage/unstage hunk (#265)
1 parent b9ed098 commit b7e0e38

18 files changed

+688
-120
lines changed

src/Commands/Diff.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public partial class Diff : Command
1414

1515
public Diff(string repo, Models.DiffOption opt, int unified)
1616
{
17+
_result.TextDiff = new Models.TextDiff() {
18+
Repo = repo,
19+
Option = opt,
20+
};
21+
1722
WorkingDirectory = repo;
1823
Context = repo;
1924
Args = $"diff --ignore-cr-at-eol --unified={unified} {opt}";
@@ -214,7 +219,7 @@ private void ProcessInlineHighlights()
214219
}
215220
}
216221

217-
private readonly Models.DiffResult _result = new Models.DiffResult() { TextDiff = new Models.TextDiff() };
222+
private readonly Models.DiffResult _result = new Models.DiffResult();
218223
private readonly List<Models.TextDiffLine> _deleted = new List<Models.TextDiffLine>();
219224
private readonly List<Models.TextDiffLine> _added = new List<Models.TextDiffLine>();
220225
private int _oldLine = 0;

src/Models/DiffResult.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public partial class TextDiff
6666
public Vector SyncScrollOffset { get; set; } = Vector.Zero;
6767
public int MaxLineNumber = 0;
6868

69+
public string Repo { get; set; } = null;
70+
public DiffOption Option { get; set; } = null;
71+
6972
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
7073
{
7174
var isTracked = !string.IsNullOrEmpty(fileBlobGuid);

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@
307307
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">Find next match</x:String>
308308
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">Find previous match</x:String>
309309
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">Open search panel</x:String>
310+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">Stage Hunk</x:String>
311+
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">Unstage Hunk</x:String>
312+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Discard Hunk</x:String>
310313
<x:String x:Key="Text.Init" xml:space="preserve">Initialize Repository</x:String>
311314
<x:String x:Key="Text.Init.Path" xml:space="preserve">Path:</x:String>
312315
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Invalid repository detected. Run `git init` under this path?</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@
310310
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">定位到下一个匹配搜索的位置</x:String>
311311
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">定位到上一个匹配搜索的位置</x:String>
312312
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">打开搜索</x:String>
313+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暂存片断</x:String>
314+
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">移出暂存区</x:String>
315+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丢弃片断</x:String>
313316
<x:String x:Key="Text.Init" xml:space="preserve">初始化新仓库</x:String>
314317
<x:String x:Key="Text.Init.Path" xml:space="preserve">路径 :</x:String>
315318
<x:String x:Key="Text.Init.Tip" xml:space="preserve">选择目录不是有效的Git仓库。是否需要在此目录执行`git init`操作?</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@
310310
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">定位到下一個匹配搜尋的位置</x:String>
311311
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">定位到上一個匹配搜尋的位置</x:String>
312312
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">開啟搜尋</x:String>
313+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暫存片斷</x:String>
314+
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">移出暫存區</x:String>
315+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丟棄片斷</x:String>
313316
<x:String x:Key="Text.Init" xml:space="preserve">初始化新倉庫</x:String>
314317
<x:String x:Key="Text.Init.Path" xml:space="preserve">路徑 :</x:String>
315318
<x:String x:Key="Text.Init.Tip" xml:space="preserve">選擇目錄不是有效的Git倉庫。是否需要在此目錄執行`git init`操作?</x:String>

src/ViewModels/DiffContext.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@ namespace SourceGit.ViewModels
1212
{
1313
public class DiffContext : ObservableObject
1414
{
15-
public string RepositoryPath
16-
{
17-
get => _repo;
18-
}
19-
20-
public Models.Change WorkingCopyChange
21-
{
22-
get => _option.WorkingCopyChange;
23-
}
24-
25-
public bool IsUnstaged
26-
{
27-
get => _option.IsUnstaged;
28-
}
29-
3015
public string Title
3116
{
3217
get => _title;

src/ViewModels/TwoSideTextDiff.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ public Vector SyncScrollOffset
1717
set => SetProperty(ref _syncScrollOffset, value);
1818
}
1919

20+
public Models.DiffOption Option
21+
{
22+
get;
23+
set;
24+
}
25+
2026
public TwoSideTextDiff(Models.TextDiff diff, TwoSideTextDiff previous = null)
2127
{
2228
File = diff.File;
2329
MaxLineNumber = diff.MaxLineNumber;
30+
Option = diff.Option;
2431

2532
foreach (var line in diff.Lines)
2633
{

src/Views/BranchCompare.axaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@
132132

133133
<!-- Changes -->
134134
<Border Grid.Row="1" Margin="0,4,0,0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}">
135-
<v:ChangeCollectionView IsWorkingCopyChange="False"
136-
ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}"
135+
<v:ChangeCollectionView ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}"
137136
Changes="{Binding VisibleChanges}"
138137
SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
139138
ContextRequested="OnChangeContextRequested"/>

src/Views/ChangeCollectionView.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
IsChecked="{Binding IsExpanded}"
5757
IsVisible="{Binding IsFolder}"/>
5858

59-
<v:ChangeStatusIcon Grid.Column="1" Width="14" Height="14" IsWorkingCopyChange="{Binding #ThisControl.IsWorkingCopyChange}" Change="{Binding Change}" IsVisible="{Binding !IsFolder}"/>
59+
<v:ChangeStatusIcon Grid.Column="1" Width="14" Height="14" IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}" Change="{Binding Change}" IsVisible="{Binding !IsFolder}"/>
6060
<TextBlock Grid.Column="2" Classes="monospace" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}" Margin="6,0,0,0"/>
6161
</Grid>
6262
</DataTemplate>
@@ -75,7 +75,7 @@
7575
<v:ChangeStatusIcon Grid.Column="0"
7676
Width="14" Height="14"
7777
Margin="4,0,0,0"
78-
IsWorkingCopyChange="{Binding #ThisControl.IsWorkingCopyChange}"
78+
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
7979
Change="{Binding}" />
8080

8181
<TextBlock Grid.Column="1"
@@ -104,7 +104,7 @@
104104
<v:ChangeStatusIcon Grid.Column="0"
105105
Width="14" Height="14"
106106
Margin="4,0,0,0"
107-
IsWorkingCopyChange="{Binding #ThisControl.IsWorkingCopyChange}"
107+
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
108108
Change="{Binding}" />
109109

110110
<TextBlock Grid.Column="1"

src/Views/ChangeCollectionView.axaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ protected override void OnKeyDown(KeyEventArgs e)
4040

4141
public partial class ChangeCollectionView : UserControl
4242
{
43-
public static readonly StyledProperty<bool> IsWorkingCopyChangeProperty =
44-
AvaloniaProperty.Register<ChangeCollectionView, bool>(nameof(IsWorkingCopyChange));
43+
public static readonly StyledProperty<bool> IsUnstagedChangeProperty =
44+
AvaloniaProperty.Register<ChangeCollectionView, bool>(nameof(IsUnstagedChange));
4545

46-
public bool IsWorkingCopyChange
46+
public bool IsUnstagedChange
4747
{
48-
get => GetValue(IsWorkingCopyChangeProperty);
49-
set => SetValue(IsWorkingCopyChangeProperty, value);
48+
get => GetValue(IsUnstagedChangeProperty);
49+
set => SetValue(IsUnstagedChangeProperty, value);
5050
}
5151

5252
public static readonly StyledProperty<SelectionMode> SelectionModeProperty =

0 commit comments

Comments
 (0)