Skip to content

Commit 1df0de8

Browse files
committed
fix(flatpak): use flatpak-spawn --host for git and add Flatpak D-Bus permission
1 parent 3002a0e commit 1df0de8

8 files changed

Lines changed: 32 additions & 29 deletions

File tree

packaging/flatpak/com.cst8t.gitmun.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ finish-args:
1010
- --socket=wayland
1111
- --device=dri
1212
- --filesystem=home
13+
- --talk-name=org.freedesktop.Flatpak
1314

1415
modules:
1516
- name: gitmun-files

src-tauri/src/avatar/forgejo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::conditional::ConditionalProvider;
22
use base64::{engine::general_purpose::STANDARD, Engine};
33
use std::fs;
44
use std::path::Path;
5-
use std::process::Command;
65
use url::Url;
76

87
// Forgejo/Gitea hash avatars using HMAC-SHA1 with an instance-secret, so
@@ -228,7 +227,7 @@ impl ForgejoProvider {
228227
}
229228

230229
fn find_local_commit_sha(email: &str, repo_path: &str) -> Option<String> {
231-
let output = Command::new("git")
230+
let output = crate::git_command()
232231
.arg("-C")
233232
.arg(repo_path)
234233
.arg("log")

src-tauri/src/commands/history.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::git::types::{
44
RebaseResult, RepoRequest, ResetRequest, RevertCommitRequest, SignatureStatus,
55
};
66
use crate::AppState;
7-
use std::process::Command;
87
use std::time::{SystemTime, UNIX_EPOCH};
98
use tauri::Manager;
109

@@ -37,15 +36,10 @@ pub async fn verify_commits(
3736
}
3837

3938
tauri::async_runtime::spawn_blocking(move || -> Result<Vec<CommitVerification>, String> {
40-
#[cfg(windows)]
41-
const GIT: &str = "git.exe";
42-
#[cfg(not(windows))]
43-
const GIT: &str = "git";
44-
4539
// Read the allowedSignersFile path directly from git config. This is
4640
// more reliable than detecting from stderr, since error message wording
4741
// can change across git versions.
48-
let configured_signers = Command::new(GIT)
42+
let configured_signers = crate::git_command()
4943
.current_dir(&repo_path)
5044
.args(["config", "--get", "gpg.ssh.allowedSignersFile"])
5145
.output()
@@ -90,7 +84,7 @@ pub async fn verify_commits(
9084
None
9185
};
9286

93-
let mut cmd = Command::new(GIT);
87+
let mut cmd = crate::git_command();
9488
cmd.current_dir(&repo_path);
9589
if let Some(ref path) = signers_override {
9690
cmd.arg("-c")

src-tauri/src/commands/repo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::git::types::{
77
};
88
use crate::{configure_command, AppState, CloneCancelFlag};
99
use std::io::Read;
10-
use std::process::{Command, Stdio};
10+
use std::process::Stdio;
1111
use std::sync::atomic::Ordering;
1212
use tauri::Manager;
1313

@@ -79,15 +79,15 @@ pub fn init_repo(repo_path: String) -> Result<OperationResult, String> {
7979
});
8080
}
8181

82-
let mut command = Command::new("git");
82+
let mut command = crate::git_command();
8383
configure_command(&mut command);
8484
command.arg("init").arg("-b").arg("main").current_dir(&path);
8585
let output = command
8686
.output()
8787
.map_err(|e| format!("Failed to launch git: {e}"))?;
8888

8989
if !output.status.success() {
90-
let mut fallback = Command::new("git");
90+
let mut fallback = crate::git_command();
9191
configure_command(&mut fallback);
9292
fallback.arg("init").current_dir(&path);
9393
let fallback_output = fallback
@@ -130,7 +130,7 @@ pub async fn clone_repo(
130130
let dest_existed = final_dest.exists();
131131
let cleanup_path = final_dest_str.clone();
132132

133-
let mut cmd = Command::new("git");
133+
let mut cmd = crate::git_command();
134134
configure_command(&mut cmd);
135135
cmd.args(["clone", "--progress", &repo_url, &final_dest_str])
136136
.stderr(Stdio::piped())

src-tauri/src/commands/settings.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::git::types::{
22
AvatarProviderMode, BackendMode, CommitDateMode, ExternalDiffTool, LinuxGraphicsMode,
33
OperationResult, Settings, ThemeMode,
44
};
5-
use crate::{configure_command, AppState};
6-
use std::process::Command;
5+
use crate::{configure_command, git_command, AppState};
76
use tauri::Manager;
87

98
#[tauri::command]
@@ -97,7 +96,7 @@ pub fn get_global_default_branch() -> Result<Option<String>, String> {
9796
}
9897

9998
fn git_config_global_set(key: &str, value: &str) -> Result<(), String> {
100-
let mut command = Command::new("git");
99+
let mut command = git_command();
101100
configure_command(&mut command);
102101
let output = command
103102
.args(["config", "--global", key, value])
@@ -115,7 +114,7 @@ fn git_config_global_set(key: &str, value: &str) -> Result<(), String> {
115114
}
116115

117116
fn git_config_global_get(key: &str) -> Result<Option<String>, String> {
118-
let mut command = Command::new("git");
117+
let mut command = git_command();
119118
configure_command(&mut command);
120119
let output = command
121120
.args(["config", "--global", "--get", key])
@@ -143,7 +142,7 @@ fn git_config_global_get(key: &str) -> Result<Option<String>, String> {
143142
}
144143

145144
fn validate_branch_name(name: &str) -> Result<(), String> {
146-
let mut command = Command::new("git");
145+
let mut command = git_command();
147146
configure_command(&mut command);
148147
let output = command
149148
.args(["check-ref-format", "--branch", name])
@@ -163,7 +162,7 @@ fn validate_branch_name(name: &str) -> Result<(), String> {
163162
}
164163

165164
fn git_config_global_unset(key: &str) -> Result<(), String> {
166-
let mut command = Command::new("git");
165+
let mut command = git_command();
167166
configure_command(&mut command);
168167
// --unset exits 5 when the key doesn't exist - treat that as success
169168
let output = command

src-tauri/src/git/cli.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl CliGitHandler {
101101
}
102102

103103
fn run_git_bytes(args: &[&str], current_dir: Option<&Path>) -> GitResult<Vec<u8>> {
104-
let mut command = Command::new("git");
104+
let mut command = crate::git_command();
105105
Self::configure_command(&mut command);
106106
command.args(args);
107107

@@ -178,7 +178,7 @@ impl CliGitHandler {
178178
args: &[&str],
179179
current_dir: Option<&Path>,
180180
) -> GitResult<()> {
181-
let mut command = Command::new("git");
181+
let mut command = crate::git_command();
182182
Self::configure_command(&mut command);
183183
command.args(overrides.iter().map(String::as_str)).args(args);
184184
if let Some(path) = current_dir {
@@ -208,7 +208,7 @@ impl CliGitHandler {
208208
current_dir: Option<&Path>,
209209
extra_ok_codes: &[i32],
210210
) -> GitResult<String> {
211-
let mut command = Command::new("git");
211+
let mut command = crate::git_command();
212212
Self::configure_command(&mut command);
213213
command.args(args);
214214

@@ -456,7 +456,7 @@ impl CliGitHandler {
456456
current_dir: &Path,
457457
stdin_data: &[u8],
458458
) -> GitResult<String> {
459-
let mut command = Command::new("git");
459+
let mut command = crate::git_command();
460460
Self::configure_command(&mut command);
461461
command
462462
.args(args)
@@ -607,7 +607,7 @@ impl CliGitHandler {
607607
}
608608

609609
fn get_diff_tool_name(repo_path: &Path) -> Option<String> {
610-
let mut command = Command::new("git");
610+
let mut command = crate::git_command();
611611
Self::configure_command(&mut command);
612612
let output = command
613613
.args(["config", "--get", "diff.tool"])
@@ -637,7 +637,7 @@ impl CliGitHandler {
637637
}
638638

639639
fn get_merge_tool_name(repo_path: &Path) -> Option<String> {
640-
let mut command = Command::new("git");
640+
let mut command = crate::git_command();
641641
Self::configure_command(&mut command);
642642
let output = command
643643
.args(["config", "--get", "merge.tool"])
@@ -718,7 +718,7 @@ impl CliGitHandler {
718718
cmd
719719
}
720720
_ => {
721-
let mut cmd = Command::new("git");
721+
let mut cmd = crate::git_command();
722722
Self::configure_command(&mut cmd);
723723
cmd.args(Self::difftool_cmd_overrides(tool_name))
724724
.args(["difftool", "-y", "--tool", tool_name, "--no-index", "--"])

src-tauri/src/git/gix_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl GixGitHandler {
559559

560560
fn detect_conflicted_files(git_dir: &Path) -> Vec<ConflictFileItem> {
561561
let repo_path = git_dir.parent().unwrap_or(git_dir);
562-
let output = std::process::Command::new("git")
562+
let output = crate::git_command()
563563
.args(["-c", "core.quotepath=false", "status", "--porcelain=v1"])
564564
.current_dir(repo_path)
565565
.output()
@@ -609,7 +609,7 @@ impl GixGitHandler {
609609
}
610610

611611
fn collect_numstat(repo_path: &Path, staged: bool) -> HashMap<String, (u32, u32)> {
612-
let mut command = std::process::Command::new("git");
612+
let mut command = crate::git_command();
613613
command.arg("-c").arg("core.quotepath=false").arg("diff");
614614
if staged {
615615
command.arg("--cached");

src-tauri/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub(crate) fn configure_command(_command: &mut std::process::Command) {
3131
}
3232
}
3333

34+
pub(crate) fn git_command() -> std::process::Command {
35+
#[cfg(target_os = "linux")]
36+
if std::env::var_os("FLATPAK_ID").is_some() {
37+
let mut cmd = std::process::Command::new("flatpak-spawn");
38+
cmd.args(["--host", "git"]);
39+
return cmd;
40+
}
41+
std::process::Command::new("git")
42+
}
43+
3444
/// Read linuxGraphicsMode from the saved config file without starting Tauri.
3545
/// Used to apply WebKit env vars before the WebView is initialised.
3646
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)