Skip to content

Commit

Permalink
chore(friendshipper): show git cmds running during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rudoi committed Oct 15, 2024
1 parent 0a1f1d9 commit 5b51e77
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
29 changes: 24 additions & 5 deletions core/src/clients/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct Opts<'a> {
pub should_log_stdout: bool,
pub return_complete_error: bool,
pub lfs_mode: LfsMode,
pub skip_notify_frontend: bool,
}

#[derive(Clone, Debug, Default)]
Expand All @@ -120,6 +121,7 @@ impl Default for Opts<'_> {
should_log_stdout: true,
return_complete_error: false,
lfs_mode: LfsMode::Inflated,
skip_notify_frontend: false,
}
}
}
Expand All @@ -131,6 +133,7 @@ impl Opts<'_> {
should_log_stdout: true,
return_complete_error: false,
lfs_mode: LfsMode::Inflated,
skip_notify_frontend: false,
}
}

Expand All @@ -140,6 +143,7 @@ impl Opts<'_> {
should_log_stdout: false,
return_complete_error: false,
lfs_mode: LfsMode::Inflated,
skip_notify_frontend: false,
}
}

Expand All @@ -149,6 +153,7 @@ impl Opts<'_> {
should_log_stdout: true,
return_complete_error: true,
lfs_mode: LfsMode::Inflated,
skip_notify_frontend: false,
}
}

Expand All @@ -161,6 +166,11 @@ impl Opts<'_> {
self.lfs_mode = LfsMode::Stubs;
self
}

pub fn with_skip_notify_frontend(mut self) -> Self {
self.skip_notify_frontend = true;
self
}
}

pub fn parse_bool_string(bool_str: &str) -> anyhow::Result<bool> {
Expand Down Expand Up @@ -209,7 +219,7 @@ impl Git {
Ok(commit.to_string())
}

pub async fn fetch(&self, prune: ShouldPrune) -> anyhow::Result<()> {
pub async fn fetch<'a>(&self, prune: ShouldPrune, opts: Opts<'a>) -> anyhow::Result<()> {
if prune == ShouldPrune::Yes {
self.run(
&[
Expand All @@ -218,13 +228,13 @@ impl Git {
"--no-auto-maintenance",
"--show-forced-updates",
],
Opts::default(),
opts,
)
.await
} else {
self.run(
&["fetch", "--no-auto-maintenance", "--show-forced-updates"],
Opts::default(),
opts,
)
.await
}
Expand Down Expand Up @@ -665,6 +675,11 @@ impl Git {
.await
}

pub async fn run_gc(&self) -> anyhow::Result<()> {
self.run(&["gc", "--aggressive", "--prune=now"], Opts::default())
.await
}

// sample output of: git worktree list --porcelain
// worktree D:/repos/fellowship
// HEAD 6ca1438e074b664470df54319cd6272a4d4d565d
Expand All @@ -682,6 +697,7 @@ impl Git {
should_log_stdout: false,
return_complete_error: true,
lfs_mode: LfsMode::Stubs,
skip_notify_frontend: false,
},
)
.await?;
Expand Down Expand Up @@ -830,9 +846,12 @@ impl Git {
)
};

if let Err(e) = self.tx.send(message) {
warn!("Failed to send git command message: {}", e);
if !opts.skip_notify_frontend {
if let Err(e) = self.tx.send(message) {
warn!("Failed to send git command message: {}", e);
}
}

let mut cmd = Command::new("git");
for arg in args {
cmd.arg(arg);
Expand Down
10 changes: 9 additions & 1 deletion core/src/clients/git_maintenance_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::sync::Arc;
use std::time::Duration;
use tracing::{error, info, warn};

use super::git::Opts;

pub struct GitMaintenanceRunner {
git: Git,
config: MaintenanceConfig,
Expand Down Expand Up @@ -52,7 +54,13 @@ impl GitMaintenanceRunner {
let fetch_task = tokio::task::spawn(async move {
loop {
if !pause.clone().load(std::sync::atomic::Ordering::Relaxed) {
match git.fetch(ShouldPrune::Yes).await {
match git
.fetch(
ShouldPrune::Yes,
Opts::default().with_skip_notify_frontend(),
)
.await
{
Ok(_) => {}
Err(e) => {
warn!("Error fetching: {:?}", e);
Expand Down
4 changes: 3 additions & 1 deletion friendshipper/src-tauri/src/repo/operations/update_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ where
);

let did_stash = self.git_client.stash(git::StashAction::Push).await?;
self.git_client.fetch(git::ShouldPrune::Yes).await?;
self.git_client
.fetch(git::ShouldPrune::Yes, git::Opts::default())
.await?;
self.git_client.checkout(&commit_sha_short).await?;
if did_stash {
self.git_client.stash(git::StashAction::Pop).await?;
Expand Down
4 changes: 3 additions & 1 deletion friendshipper/src-tauri/src/repo/project/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ where
);

let git_client = git::Git::new(engine_path, state.git_tx.clone());
git_client.fetch(ShouldPrune::No).await?;
git_client
.fetch(ShouldPrune::No, git::Opts::default())
.await?;
git_client.checkout(&engine_commit).await?;

let solution = SolutionParams {
Expand Down
3 changes: 3 additions & 0 deletions friendshipper/src-tauri/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ impl Server {
git.set_config("http.postBuffer", "524288000").await?;
git.configure_untracked_cache().await?;

startup_tx.send("Performing git repo maintenance".to_string())?;
git.run_gc().await?;

startup_tx.send("Installing git hooks".to_string())?;
if let Some(git_hooks_path) = git_hooks_path {
tokio::spawn(async move {
Expand Down
2 changes: 1 addition & 1 deletion friendshipper/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"title": "Friendshipper",
"minWidth": 980,
"minHeight": 600,
"visible": false,
"visible": true,
"decorations": false,
"transparent": true,
"fileDropEnabled": false
Expand Down
29 changes: 25 additions & 4 deletions friendshipper/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
let loginPrompted = false;
let loadingBuilds = false;
let startupMessage = 'Initializing Friendshipper';
let gitStartupMessage = '';
// Refresh timer
let lastRefresh = new Date().getTime();
Expand Down Expand Up @@ -303,6 +304,10 @@
await appWindow.show();
};
const unlisten = listen('startup-message', (e) => {
startupMessage = e.payload as string;
});
void setupAppWindow();
const refresh = async () => {
Expand Down Expand Up @@ -394,6 +399,12 @@
void emit('error', e);
}
});
return () => {
void unlisten.then((f) => {
f();
});
};
});
void listen('error', (e) => {
Expand All @@ -406,15 +417,20 @@
}
});
void listen('git-log', (event) => {
// git-log "Updating files: 1%" etc too long, filter out and show static string
if (event.payload.startsWith('Updating files: ')) {
gitStartupMessage = 'Updating files...';
} else {
gitStartupMessage = event.payload as string;
}
});
void listen('success', (e) => {
successMessage = e.payload as string;
hasSuccess = true;
});
void listen('startup-message', (e) => {
startupMessage = e.payload as string;
});
void listen('git-refresh', () => {
void refreshRepo();
});
Expand Down Expand Up @@ -548,6 +564,11 @@
<span class="text-gray-300 text-xl">{startupMessage}...</span>
<Spinner size="4" />
</div>
{#if gitStartupMessage}
<div class="rounded-md p-2 bg-secondary-800 dark:bg-space-950">
<code class="text-sm text-gray-300 dark:text-gray-300 m-0">{gitStartupMessage}</code>
</div>
{/if}
<Button on:click={openSystemLogsFolder}>Open Logs Folder</Button>
</div>
{/if}
Expand Down

0 comments on commit 5b51e77

Please sign in to comment.