Compare commits

...

6 commits

Author SHA1 Message Date
leo
bcc43e167c
ux: remove bottom line of selected tab in main tabbar
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
2024-09-27 11:34:47 +08:00
leo
5a536fae06
ux: auto-fetch interval input size 2024-09-27 11:25:36 +08:00
leo
130c98ad40
feature: supports search commit only in current branch 2024-09-27 11:17:02 +08:00
leo
027844f4c5
ux: reorder reset modes by safety 2024-09-27 09:53:04 +08:00
leo
304b175b4b
refactor: remove context menu items about LFS tracking from changes and revision files 2024-09-27 09:46:02 +08:00
leo
9ff28dff72
feature: add git LFS context menu items for changes and revision files in commit details view 2024-09-27 09:39:25 +08:00
17 changed files with 155 additions and 52 deletions

View file

@ -14,21 +14,23 @@ namespace SourceGit.Commands
_findFirstMerged = needFindHead;
}
public QueryCommits(string repo, string filter, Models.CommitSearchMethod method)
public QueryCommits(string repo, string filter, Models.CommitSearchMethod method, bool onlyCurrentBranch)
{
string search;
string search = onlyCurrentBranch ? string.Empty : "--branches --remotes ";
if (method == Models.CommitSearchMethod.ByUser)
{
search = $"-i --author=\"{filter}\" --committer=\"{filter}\"";
search += $"-i --author=\"{filter}\" --committer=\"{filter}\"";
}
else if (method == Models.CommitSearchMethod.ByFile)
{
search = $"-- \"{filter}\"";
search += $"-- \"{filter}\"";
}
else
{
var argsBuilder = new StringBuilder();
argsBuilder.Append(search);
var words = filter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var word in words)
{
@ -36,12 +38,13 @@ namespace SourceGit.Commands
argsBuilder.Append($"--grep=\"{escaped}\" ");
}
argsBuilder.Append("--all-match -i");
search = argsBuilder.ToString();
}
WorkingDirectory = repo;
Context = repo;
Args = $"log -1000 --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s --branches --remotes " + search;
Args = $"log -1000 --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s " + search;
_findFirstMerged = false;
}

View file

@ -8,9 +8,9 @@ namespace SourceGit.Models
[
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Purple),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Purple),
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Green),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Green),
];
public string Name { get; set; }

View file

@ -512,7 +512,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">REMOTE HINZUFÜGEN</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">KONFLIKTE BEHEBEN</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Commit suchen</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Suche über</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Dateiname</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Commit-Nachricht</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -509,11 +509,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVE</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Search Commit</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Search By</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">Author &amp; Committer</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">Show Tags as Tree</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">Statistics</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">SUBMODULES</x:String>

View file

@ -491,7 +491,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVE</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Search Commit</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Search By</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -484,7 +484,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADICIONAR REMOTO</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVER</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Pesquisar Commit</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Pesquisar Por</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Arquivo</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Mensagem</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -1,4 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://SourceGit/Resources/Locales/en_US.axaml"/>
</ResourceDictionary.MergedDictionaries>
<x:String x:Key="Text.About" xml:space="preserve">О программе</x:String>
<x:String x:Key="Text.About.Menu" xml:space="preserve">О SourceGit</x:String>
<x:String x:Key="Text.About.BuildWith" xml:space="preserve">• Сборка с </x:String>
@ -507,7 +510,6 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ДОБАВИТЬ ВНЕШНЕЕ ХРАНИЛИЩЕ</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">РАЗРЕШИТЬ</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Поиск фиксации</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Поиск по</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">Файл</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Сообщение</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>

View file

@ -507,11 +507,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">添加远程</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解决冲突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">查找提交</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">搜索途径</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交信息</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以树型结构展示</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交统计</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模块列表</x:String>

View file

@ -512,11 +512,11 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">新增遠端</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解決衝突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">搜尋提交</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">搜尋方式</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交訊息</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交編號</x:String>
<x:String x:Key="Text.Repository.Search.ByUser" xml:space="preserve">作者及提交者</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋當前分支</x:String>
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以樹型結構展示</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交統計</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模組列表</x:String>

View file

@ -321,6 +321,9 @@ namespace SourceGit.ViewModels
menu.Items.Add(resetToFirstParent);
menu.Items.Add(new MenuItem { Header = "-" });
if (File.Exists(Path.Combine(fullPath)))
TryToAddContextMenuItemsForGitLFS(menu, change.Path);
var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath");
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
@ -346,6 +349,7 @@ namespace SourceGit.ViewModels
public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
{
var menu = new ContextMenu();
var fullPath = Path.Combine(_repo.FullPath, file.Path);
var explore = new MenuItem();
explore.Header = App.Text("RevealFile");
@ -385,6 +389,10 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
menu.Items.Add(explore);
menu.Items.Add(saveAs);
menu.Items.Add(new MenuItem() { Header = "-" });
var history = new MenuItem();
history.Header = App.Text("FileHistory");
history.Icon = App.CreateMenuIcon("Icons.Histories");
@ -406,6 +414,10 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
menu.Items.Add(history);
menu.Items.Add(blame);
menu.Items.Add(new MenuItem() { Header = "-" });
var resetToThisRevision = new MenuItem();
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
@ -428,6 +440,13 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
menu.Items.Add(resetToThisRevision);
menu.Items.Add(resetToFirstParent);
menu.Items.Add(new MenuItem() { Header = "-" });
if (File.Exists(Path.Combine(fullPath)))
TryToAddContextMenuItemsForGitLFS(menu, file.Path);
var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath");
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
@ -446,16 +465,6 @@ namespace SourceGit.ViewModels
e.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(explore);
menu.Items.Add(saveAs);
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(history);
menu.Items.Add(blame);
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(resetToThisRevision);
menu.Items.Add(resetToFirstParent);
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(copyPath);
menu.Items.Add(copyFileName);
return menu;
@ -532,6 +541,90 @@ namespace SourceGit.ViewModels
}
}
private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
{
var lfsEnabled = new Commands.LFS(_repo.FullPath).IsEnabled();
if (!lfsEnabled)
return;
var lfs = new MenuItem();
lfs.Header = App.Text("GitLFS");
lfs.Icon = App.CreateMenuIcon("Icons.LFS");
var lfsLock = new MenuItem();
lfsLock.Header = App.Text("GitLFS.Locks.Lock");
lfsLock.Icon = App.CreateMenuIcon("Icons.Lock");
lfsLock.IsEnabled = _repo.Remotes.Count > 0;
if (_repo.Remotes.Count == 1)
{
lfsLock.Click += async (_, e) =>
{
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(_repo.Remotes[0].Name, path));
if (succ)
App.SendNotification(_repo.FullPath, $"Lock file \"{path}\" successfully!");
e.Handled = true;
};
}
else
{
foreach (var remote in _repo.Remotes)
{
var remoteName = remote.Name;
var lockRemote = new MenuItem();
lockRemote.Header = remoteName;
lockRemote.Click += async (_, e) =>
{
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Lock(remoteName, path));
if (succ)
App.SendNotification(_repo.FullPath, $"Lock file \"{path}\" successfully!");
e.Handled = true;
};
lfsLock.Items.Add(lockRemote);
}
}
lfs.Items.Add(lfsLock);
var lfsUnlock = new MenuItem();
lfsUnlock.Header = App.Text("GitLFS.Locks.Unlock");
lfsUnlock.Icon = App.CreateMenuIcon("Icons.Unlock");
lfsUnlock.IsEnabled = _repo.Remotes.Count > 0;
if (_repo.Remotes.Count == 1)
{
lfsUnlock.Click += async (_, e) =>
{
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(_repo.Remotes[0].Name, path, false));
if (succ)
App.SendNotification(_repo.FullPath, $"Unlock file \"{path}\" successfully!");
e.Handled = true;
};
}
else
{
foreach (var remote in _repo.Remotes)
{
var remoteName = remote.Name;
var unlockRemote = new MenuItem();
unlockRemote.Header = remoteName;
unlockRemote.Click += async (_, e) =>
{
var succ = await Task.Run(() => new Commands.LFS(_repo.FullPath).Unlock(remoteName, path, false));
if (succ)
App.SendNotification(_repo.FullPath, $"Unlock file \"{path}\" successfully!");
e.Handled = true;
};
lfsUnlock.Items.Add(unlockRemote);
}
}
lfs.Items.Add(lfsUnlock);
menu.Items.Add(lfs);
menu.Items.Add(new MenuItem() { Header = "-" });
}
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
private static partial Regex REG_LFS_FORMAT();

View file

@ -65,7 +65,7 @@ namespace SourceGit.ViewModels
CallUIThread(() =>
{
_repo.MarkFetched();
_repo.SetWatcherEnabled(true);
_repo.SetWatcherEnabled(true);
});
return true;

View file

@ -20,7 +20,7 @@ namespace SourceGit.ViewModels
get => _isLoading;
private set => SetProperty(ref _isLoading, value);
}
public bool ShowOnlyMyLocks
{
get => _showOnlyMyLocks;

View file

@ -210,6 +210,12 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _isSearchLoadingVisible, value);
}
public bool OnlySearchCommitsInCurrentBranch
{
get => _onlySearchCommitsInCurrentBranch;
set => SetProperty(ref _onlySearchCommitsInCurrentBranch, value);
}
public int SearchCommitFilterType
{
get => _searchCommitFilterType;
@ -589,13 +595,13 @@ namespace SourceGit.ViewModels
visible.Add(commit);
break;
case 1:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByUser).Result();
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByUser, _onlySearchCommitsInCurrentBranch).Result();
break;
case 2:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByMessage).Result();
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByMessage, _onlySearchCommitsInCurrentBranch).Result();
break;
case 3:
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByFile).Result();
visible = new Commands.QueryCommits(_fullpath, _searchCommitFilter, Models.CommitSearchMethod.ByFile, _onlySearchCommitsInCurrentBranch).Result();
break;
}
@ -667,8 +673,8 @@ namespace SourceGit.ViewModels
var hasLeft = false;
foreach (var b in _branches)
{
if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) &&
!b.FullName.Equals(local.Upstream, StringComparison.Ordinal) &&
if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) &&
!b.FullName.Equals(local.Upstream, StringComparison.Ordinal) &&
!_settings.Filters.Contains(b.FullName))
{
hasLeft = true;
@ -2072,6 +2078,7 @@ namespace SourceGit.ViewModels
private bool _isSearchLoadingVisible = false;
private bool _isSearchCommitSuggestionOpen = false;
private int _searchCommitFilterType = 2;
private bool _onlySearchCommitsInCurrentBranch = false;
private bool _enableFirstParentInHistories = false;
private string _searchCommitFilter = string.Empty;
private List<Models.Commit> _searchedCommits = new List<Models.Commit>();

View file

@ -430,7 +430,7 @@ namespace SourceGit.Views
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.Repository repo &&
if (DataContext is ViewModels.Repository repo &&
sender is ToggleButton toggle &&
toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node)
{

View file

@ -58,7 +58,7 @@ namespace SourceGit.Views
var geo = new StreamGeometry();
var angle = Math.PI / 2;
var y = height + 0.1;
var y = height + 0.5;
using (var ctx = geo.Open())
{
double x;
@ -94,17 +94,17 @@ namespace SourceGit.Views
x = drawRightX;
y = 6;
ctx.ArcTo(new Point(x, y), new Size(6, 6), angle, false, SweepDirection.Clockwise);
y = height + 0.1 - 5;
y = height + 0.5 - 5;
ctx.LineTo(new Point(x, y));
x += 5;
y = height + 0.1;
y = height + 0.5;
ctx.ArcTo(new Point(x, y), new Size(5, 5), angle, false, SweepDirection.CounterClockwise);
}
else
{
x = LauncherTabsScroller.Bounds.Right;
ctx.LineTo(new Point(x, y));
y = height + 0.1;
y = height + 0.5;
ctx.LineTo(new Point(x, y));
}
}

View file

@ -343,7 +343,7 @@
</Grid>
<!-- Commit Search Panel -->
<Grid Grid.Row="1" RowDefinitions="24,32,*" Margin="8,0,4,8" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
<Grid Grid.Row="1" RowDefinitions="26,26,*" Margin="8,0,4,8" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
<!-- Search Input Box -->
<Grid Grid.Row="0">
<TextBox x:Name="TxtSearchCommitsBox"
@ -430,18 +430,11 @@
</Popup>
</Grid>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Text="{DynamicResource Text.Repository.Search.By}"
Foreground="{DynamicResource Brush.FG2}"
Margin="2,0,0,0"/>
<ComboBox Grid.Column="1"
MinHeight="24" Height="24"
Padding="8,0"
Background="{DynamicResource Brush.Contents}"
BorderBrush="{DynamicResource Brush.Border2}"
HorizontalAlignment="Right"
<StackPanel Grid.Row="1" Orientation="Horizontal">
<ComboBox MinHeight="24" Height="24"
Padding="4,0"
Background="Transparent"
BorderThickness="0"
SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}">
<ComboBox.Items>
<TextBlock Text="{DynamicResource Text.Repository.Search.BySHA}" FontSize="12"/>
@ -450,9 +443,17 @@
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/>
</ComboBox.Items>
</ComboBox>
</Grid>
<CheckBox Height="24"
Margin="4,0,0,0"
FontSize="12"
Content="{DynamicResource Text.Repository.Search.InCurrentBranch}"
IsChecked="{Binding OnlySearchCommitsInCurrentBranch, Mode=TwoWay}"
IsVisible="{Binding SearchCommitFilterType, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
</StackPanel>
<ListBox Grid.Row="2"
Margin="0,8,0,0"
ItemsSource="{Binding SearchedCommits}"
SelectionMode="Single"
SelectedItem="{Binding SearchResultSelectedCommit, Mode=TwoWay}"

View file

@ -113,7 +113,7 @@
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>
<NumericUpDown Minimum="1" Maximum="60" Increment="1"
Height="26"
Height="26" Width="110"
Margin="8,0,0,0" Padding="4"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
CornerRadius="3"