From 05dba3261478b96ea70e51ac65ff93db4278e440 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Jul 2025 16:44:00 +0800 Subject: [PATCH 1/2] fix: try to fix the issue that getting askpass for every action even when it's not necessary (#1577) Signed-off-by: leo --- build/resources/_common/applications/sourcegit.desktop | 2 +- build/resources/_common/sourcegit | 4 ++++ build/resources/appimage/sourcegit | 4 ++++ build/resources/rpm/SPECS/build.spec | 3 ++- build/scripts/package.linux.sh | 6 ++++-- src/Commands/Command.cs | 2 +- 6 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 build/resources/_common/sourcegit create mode 100644 build/resources/appimage/sourcegit diff --git a/build/resources/_common/applications/sourcegit.desktop b/build/resources/_common/applications/sourcegit.desktop index bcf9c813c..42b1bcf5e 100644 --- a/build/resources/_common/applications/sourcegit.desktop +++ b/build/resources/_common/applications/sourcegit.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Name=SourceGit Comment=Open-source & Free Git GUI Client -Exec=/opt/sourcegit/sourcegit +Exec=/usr/bin/sourcegit Icon=/usr/share/icons/sourcegit.png Terminal=false Type=Application diff --git a/build/resources/_common/sourcegit b/build/resources/_common/sourcegit new file mode 100644 index 000000000..0ff93d3a9 --- /dev/null +++ b/build/resources/_common/sourcegit @@ -0,0 +1,4 @@ +#!/bin/bash + +eval `ssh-agent -s` +/opt/sourcegit/sourcegit $@ diff --git a/build/resources/appimage/sourcegit b/build/resources/appimage/sourcegit new file mode 100644 index 000000000..b0f9ee31c --- /dev/null +++ b/build/resources/appimage/sourcegit @@ -0,0 +1,4 @@ +#!/bin/bash + +eval `ssh-agent -s` +"$APPDIR/opt/sourcegit/sourcegit" $@ diff --git a/build/resources/rpm/SPECS/build.spec b/build/resources/rpm/SPECS/build.spec index 2a684837a..0deab37a6 100644 --- a/build/resources/rpm/SPECS/build.spec +++ b/build/resources/rpm/SPECS/build.spec @@ -21,11 +21,12 @@ mkdir -p %{buildroot}/%{_bindir} mkdir -p %{buildroot}/usr/share/applications mkdir -p %{buildroot}/usr/share/icons cp -f ../../../SourceGit/* %{buildroot}/opt/sourcegit/ -ln -rsf %{buildroot}/opt/sourcegit/sourcegit %{buildroot}/%{_bindir} +cp -f ../../_common/sourcegit %{buildroot}/%{_bindir} cp -r ../../_common/applications %{buildroot}/%{_datadir} cp -r ../../_common/icons %{buildroot}/%{_datadir} chmod 755 -R %{buildroot}/opt/sourcegit chmod 755 %{buildroot}/%{_datadir}/applications/sourcegit.desktop +chmod 755 %{buildroot}/%{_bindir}/sourcegit %files %dir /opt/sourcegit/ diff --git a/build/scripts/package.linux.sh b/build/scripts/package.linux.sh index 1b4adbdcb..d1a4fdeba 100755 --- a/build/scripts/package.linux.sh +++ b/build/scripts/package.linux.sh @@ -42,7 +42,8 @@ desktop-file-install resources/_common/applications/sourcegit.desktop --dir Sour --set-icon com.sourcegit_scm.SourceGit --set-key=Exec --set-value=AppRun mv SourceGit.AppDir/usr/share/applications/{sourcegit,com.sourcegit_scm.SourceGit}.desktop cp resources/appimage/sourcegit.png SourceGit.AppDir/com.sourcegit_scm.SourceGit.png -ln -rsf SourceGit.AppDir/opt/sourcegit/sourcegit SourceGit.AppDir/AppRun +cp -f resources/appimage/sourcegit SourceGit.AppDir/AppRun +chmod 755 SourceGit.AppDir/AppRun ln -rsf SourceGit.AppDir/usr/share/applications/com.sourcegit_scm.SourceGit.desktop SourceGit.AppDir cp resources/appimage/sourcegit.appdata.xml SourceGit.AppDir/usr/share/metainfo/com.sourcegit_scm.SourceGit.appdata.xml @@ -53,9 +54,10 @@ mkdir -p resources/deb/usr/bin mkdir -p resources/deb/usr/share/applications mkdir -p resources/deb/usr/share/icons cp -f SourceGit/* resources/deb/opt/sourcegit -ln -rsf resources/deb/opt/sourcegit/sourcegit resources/deb/usr/bin +cp -f resources/_common/sourcegit resources/deb/usr/bin/ cp -r resources/_common/applications resources/deb/usr/share cp -r resources/_common/icons resources/deb/usr/share +chmod 755 resources/deb/usr/bin/sourcegit # Calculate installed size in KB installed_size=$(du -sk resources/deb | cut -f1) # Update the control file diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 11a25b369..666926cc5 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -172,7 +172,7 @@ private ProcessStartInfo CreateGitStartInfo(bool redirect) // If an SSH private key was provided, sets the environment. if (!start.Environment.ContainsKey("GIT_SSH_COMMAND") && !string.IsNullOrEmpty(SSHKey)) - start.Environment.Add("GIT_SSH_COMMAND", $"ssh -i '{SSHKey}'"); + start.Environment.Add("GIT_SSH_COMMAND", $"ssh -o AddKeysToAgent=yes -i {SSHKey.Quoted()}"); // Force using en_US.UTF-8 locale if (OperatingSystem.IsLinux()) From 31bfa1bd088b000e11a25f7c524eeaaf534748cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=AE=E3=83=A3=E3=83=83=E3=83=97?= Date: Mon, 21 Jul 2025 11:53:36 +0200 Subject: [PATCH 2/2] feat: Add depth parameter to Fetch and Pull operations (#1605) Enhanced the Fetch and Pull classes to support a new `depth` parameter for specifying operation depth. Introduced properties in RepositorySettings for managing fetch and pull depth settings. Updated localization files to include new depth-related strings. Modified AddRemote and UI components to accommodate the new depth functionality, allowing user configuration of fetch and pull depth. --- src/Commands/Fetch.cs | 5 ++- src/Commands/Pull.cs | 5 ++- src/Models/RepositorySettings.cs | 24 +++++++++++++ src/Resources/Locales/en_US.axaml | 2 ++ src/ViewModels/AddRemote.cs | 2 +- src/ViewModels/Fetch.cs | 5 +-- src/ViewModels/Pull.cs | 3 +- src/ViewModels/Repository.cs | 2 +- src/ViewModels/RepositoryConfigure.cs | 52 +++++++++++++++++++++++++++ src/Views/RepositoryConfigure.axaml | 36 ++++++++++++++++++- 10 files changed, 128 insertions(+), 8 deletions(-) diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index d25cc80c8..43cd18cbb 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Fetch : Command { - public Fetch(string repo, string remote, bool noTags, bool force) + public Fetch(string repo, string remote, bool noTags, bool force, int depth) { _remoteKey = $"remote.{remote}.sshkey"; @@ -20,6 +20,9 @@ public Fetch(string repo, string remote, bool noTags, bool force) if (force) Args += "--force "; + if (depth > 0) + Args += $"--depth={depth} "; + Args += remote; } diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index 93896c754..bdc3d41ea 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Pull : Command { - public Pull(string repo, string remote, string branch, bool useRebase) + public Pull(string repo, string remote, string branch, bool useRebase, int depth) { _remote = remote; @@ -15,6 +15,9 @@ public Pull(string repo, string remote, string branch, bool useRebase) if (useRebase) Args += "--rebase=true "; + if (depth > 0) + Args += $"--depth={depth} "; + Args += $"{remote} {branch}"; } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index f287826c5..46c159453 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -230,6 +230,30 @@ public string LastCommitMessage set; } = string.Empty; + public bool EnableFetchDepth + { + get; + set; + } = false; + + public int FetchDepthValue + { + get; + set; + } = 1; + + public bool EnablePullDepth + { + get; + set; + } = false; + + public int PullDepthValue + { + get; + set; + } = 1; + public Dictionary CollectHistoriesFilters() { var map = new Dictionary(); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 655f6e976..3e13fc059 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -193,6 +193,8 @@ Minute(s) Default Remote Preferred Merge Mode + Fetch depth + Pull depth ISSUE TRACKER Add Azure DevOps Rule Add Gerrit Change-Id Commit Rule diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index 5a6c019fc..6696ef60d 100644 --- a/src/ViewModels/AddRemote.cs +++ b/src/ViewModels/AddRemote.cs @@ -105,7 +105,7 @@ public override async Task Sure() .Use(log) .SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null); - await new Commands.Fetch(_repo.FullPath, _name, false, false) + await new Commands.Fetch(_repo.FullPath, _name, false, false, _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0) .Use(log) .RunAsync(); } diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index 0930e7773..9ee35bb97 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -60,19 +60,20 @@ public override async Task Sure() var notags = _repo.Settings.FetchWithoutTags; var force = _repo.Settings.EnableForceOnFetch; + var depth = _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0; var log = _repo.CreateLog("Fetch"); Use(log); if (FetchAllRemotes) { foreach (var remote in _repo.Remotes) - await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, depth) .Use(log) .RunAsync(); } else { - await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, depth) .Use(log) .RunAsync(); } diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index c3156536a..50d92bd99 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -145,7 +145,8 @@ public override async Task Sure() _repo.FullPath, _selectedRemote.Name, !string.IsNullOrEmpty(Current.Upstream) && Current.Upstream.Equals(_selectedBranch.FullName) ? string.Empty : _selectedBranch.Name, - UseRebase).Use(log).RunAsync(); + UseRebase, + _repo.Settings.EnablePullDepth ? _repo.Settings.PullDepthValue : 0).Use(log).RunAsync(); if (rs) { if (updateSubmodules) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 450c9e889..db145ab02 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -3138,7 +3138,7 @@ private async void AutoFetchImpl(object sender) Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); foreach (var remote in remotes) - await new Commands.Fetch(_fullpath, remote, false, false) { RaiseError = false }.RunAsync(); + await new Commands.Fetch(_fullpath, remote, false, false, _settings.EnableFetchDepth ? _settings.FetchDepthValue : 0) { RaiseError = false }.RunAsync(); _lastFetchTime = DateTime.Now; Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); } diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 72f7c2e89..2e6d9eaf5 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -101,6 +101,58 @@ public int? AutoFetchInterval } } + public bool EnableFetchDepth + { + get => _repo.Settings.EnableFetchDepth; + set + { + if (_repo.Settings.EnableFetchDepth != value) + { + _repo.Settings.EnableFetchDepth = value; + OnPropertyChanged(); + } + } + } + + public int FetchDepthValue + { + get => _repo.Settings.FetchDepthValue; + set + { + if (_repo.Settings.FetchDepthValue != value) + { + _repo.Settings.FetchDepthValue = value; + OnPropertyChanged(); + } + } + } + + public bool EnablePullDepth + { + get => _repo.Settings.EnablePullDepth; + set + { + if (_repo.Settings.EnablePullDepth != value) + { + _repo.Settings.EnablePullDepth = value; + OnPropertyChanged(); + } + } + } + + public int PullDepthValue + { + get => _repo.Settings.PullDepthValue; + set + { + if (_repo.Settings.PullDepthValue != value) + { + _repo.Settings.PullDepthValue = value; + OnPropertyChanged(); + } + } + } + public AvaloniaList CommitTemplates { get => _repo.Settings.CommitTemplates; diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index f786a3d84..14590fa9a 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -44,7 +44,7 @@ - + + + + + + + + + + + + +