From 05dba3261478b96ea70e51ac65ff93db4278e440 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Jul 2025 16:44:00 +0800 Subject: [PATCH 1/4] 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 716d608700b8241fac250819923668302d2fa631 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 13:36:32 +0200 Subject: [PATCH 2/4] enhance: Improve shared issue tracker handling in RepositoryConfigure Refactor the handling of shared issue trackers by reusing the `Commands.SharedIssueTracker` instance. Enhance the removal logic to check for the existence of the tracker file and delete it if empty. --- src/ViewModels/RepositoryConfigure.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 72f7c2e89..384e5702f 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using Avalonia.Collections; @@ -305,10 +306,26 @@ public async Task ChangeIssueTrackerShareModeAsync() if (_selectedIssueTrackerRule is not { } rule) return; + var sharedTracker = new Commands.SharedIssueTracker(_repo.FullPath); + if (rule.IsShared) - await new Commands.SharedIssueTracker(_repo.FullPath).AddAsync(rule); + await sharedTracker.AddAsync(rule); else - await new Commands.SharedIssueTracker(_repo.FullPath).RemoveAsync(rule); + { + await sharedTracker.RemoveAsync(rule); + + if ((await sharedTracker.ReadAllAsync()).Count != 0) + return; + + var filePath = Path.Combine(_repo.FullPath, ".issuetracker"); + var content = await File.ReadAllTextAsync(filePath); + + if (!string.IsNullOrEmpty(content)) + return; + + if (File.Exists(filePath)) + File.Delete(filePath); + } } public void AddNewCustomAction() From d066f2f416193d9534e8e17f36e898c881dfda8e 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 13:39:48 +0200 Subject: [PATCH 3/4] refactor --- src/ViewModels/RepositoryConfigure.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 384e5702f..1bf4d9171 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -318,9 +318,8 @@ public async Task ChangeIssueTrackerShareModeAsync() return; var filePath = Path.Combine(_repo.FullPath, ".issuetracker"); - var content = await File.ReadAllTextAsync(filePath); - if (!string.IsNullOrEmpty(content)) + if (!string.IsNullOrEmpty(await File.ReadAllTextAsync(filePath))) return; if (File.Exists(filePath)) From 15474326702f4ab7a7cd94329c3f6161b2630d4d 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 13:58:27 +0200 Subject: [PATCH 4/4] refactor: Copilot review --- src/Commands/SharedIssueTracker.cs | 24 ++++++++++++++++++++++++ src/ViewModels/RepositoryConfigure.cs | 11 +++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Commands/SharedIssueTracker.cs b/src/Commands/SharedIssueTracker.cs index 3e96fbeb7..3692d9ba4 100644 --- a/src/Commands/SharedIssueTracker.cs +++ b/src/Commands/SharedIssueTracker.cs @@ -58,6 +58,30 @@ public SharedIssueTracker(string repo) return rs; } + public async Task HasAnyAsync() + { + if (!File.Exists(_file)) + return false; + + Args = $"config -f {_file.Quoted()} -l"; + + var output = await ReadToEndAsync().ConfigureAwait(false); + + if (output.IsSuccess) + foreach (var line in output.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)) + { + var parts = line.Split('=', 2); + + if (parts.Length < 2) + continue; + + if (parts[0].StartsWith("issuetracker.", StringComparison.Ordinal)) + return true; + } + + return false; + } + public async Task AddAsync(Models.IssueTrackerRule rule) { Args = $"config -f {_file.Quoted()} issuetracker.{rule.Name.Quoted()}.regex {rule.RegexString.Quoted()}"; diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 1bf4d9171..40a5cf3dc 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -314,16 +314,15 @@ public async Task ChangeIssueTrackerShareModeAsync() { await sharedTracker.RemoveAsync(rule); - if ((await sharedTracker.ReadAllAsync()).Count != 0) + if (await sharedTracker.HasAnyAsync()) return; - + var filePath = Path.Combine(_repo.FullPath, ".issuetracker"); - if (!string.IsNullOrEmpty(await File.ReadAllTextAsync(filePath))) + if (!File.Exists(filePath) || !string.IsNullOrEmpty(await File.ReadAllTextAsync(filePath))) return; - - if (File.Exists(filePath)) - File.Delete(filePath); + + File.Delete(filePath); } }