Skip to content

Commit ed432f9

Browse files
authored
feat(desktop): complete project git workflows (#2119)
1 parent b1ef791 commit ed432f9

64 files changed

Lines changed: 5195 additions & 1385 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ jobs:
241241
with:
242242
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
243243
key: playwright-${{ runner.os }}-${{ steps.pw-version.outputs.version }}
244-
- name: Desktop build
245-
run: just desktop-build
244+
- name: Desktop E2E build
245+
run: pnpm -C desktop build:e2e
246246
- name: Desktop smoke e2e
247247
run: cd desktop && pnpm exec playwright test --project=smoke --shard=${{ matrix.shard }}/4
248248
- name: Summarize flaky tests
@@ -393,8 +393,8 @@ jobs:
393393
with:
394394
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
395395
key: playwright-${{ runner.os }}-${{ steps.pw-version.outputs.version }}
396-
- name: Desktop build
397-
run: just desktop-build
396+
- name: Desktop E2E build
397+
run: pnpm -C desktop build:e2e
398398
- name: Wait for integration services
399399
run: |
400400
wait_healthy() {

‎Justfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ desktop-e2e-integration: _ensure-migrations
248248
# Run only the e2e specs changed vs origin/main (both projects) before pushing
249249
desktop-e2e-pre-push: _ensure-migrations
250250
git fetch origin main
251-
cd {{desktop_dir}} && pnpm build && pnpm exec playwright test --only-changed=origin/main
251+
cd {{desktop_dir}} && pnpm build:e2e && pnpm exec playwright test --only-changed=origin/main
252252

253253
# Run all checks suitable for CI / pre-push (no infra needed)
254254
ci: check test-unit desktop-test desktop-build desktop-tauri-check desktop-tauri-test web-build mobile-test
@@ -340,7 +340,7 @@ mesh-e2e-confidence:
340340
desktop-screenshot *ARGS:
341341
#!/usr/bin/env bash
342342
set -euo pipefail
343-
just desktop-build
343+
pnpm -C {{desktop_dir}} build:e2e
344344
cd {{desktop_dir}}
345345
if ! curl -sf http://127.0.0.1:4173/ >/dev/null 2>&1; then
346346
python3 -m http.server 4173 -d dist >/dev/null 2>&1 &

‎desktop/package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc && vite build",
9+
"build:e2e": "tsc && vite build --mode e2e",
910
"typecheck": "tsc --noEmit",
1011
"check:file-sizes": "node ./scripts/check-file-sizes.mjs",
1112
"check:px-text": "node ./scripts/check-px-text.mjs",
@@ -16,9 +17,9 @@
1617
"test": "node --import ./test-loader.mjs --experimental-strip-types --test 'src/**/*.test.mjs'",
1718
"preview": "vite preview",
1819
"tauri": "tauri",
19-
"test:e2e": "pnpm build && playwright test",
20-
"test:e2e:smoke": "pnpm build && playwright test --project=smoke",
21-
"test:e2e:integration": "pnpm build && playwright test --project=integration",
20+
"test:e2e": "pnpm build:e2e && playwright test",
21+
"test:e2e:smoke": "pnpm build:e2e && playwright test --project=smoke",
22+
"test:e2e:integration": "pnpm build:e2e && playwright test --project=integration",
2223
"test:e2e:report": "playwright show-report",
2324
"tauri:build": "tauri build"
2425
},

‎desktop/src-tauri/src/commands/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod profile;
3737
mod project_git;
3838
mod project_git_diff;
3939
mod project_git_exec;
40+
mod project_git_workflow;
4041
mod project_repo_paths;
4142
mod project_terminal;
4243
mod relay_members;
@@ -45,6 +46,7 @@ mod social;
4546
mod team_snapshot;
4647
mod teams;
4748
mod updater;
49+
mod window_chrome;
4850
mod window_vibrancy;
4951
mod workflows;
5052
mod workspace;
@@ -84,13 +86,15 @@ pub use prevent_sleep::*;
8486
pub use profile::*;
8587
pub use project_git::*;
8688
pub use project_git_diff::*;
89+
pub use project_git_workflow::*;
8790
pub use project_terminal::*;
8891
pub use relay_members::*;
8992
pub use relay_reconnect::*;
9093
pub use social::*;
9194
pub use team_snapshot::*;
9295
pub use teams::*;
9396
pub use updater::*;
97+
pub use window_chrome::*;
9498
pub use window_vibrancy::*;
9599
pub use workflows::*;
96100
pub use workspace::*;

‎desktop/src-tauri/src/commands/project_git.rs‎

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::project_git_exec::{
2-
build_git_auth_config, clean_branch, run_git, validate_clone_url, GitAuthConfig,
2+
build_git_auth_config, clean_branch, run_git, validate_workspace_clone_url, GitAuthConfig,
33
};
44
use super::project_repo_paths::{canonical_repos_roots, find_local_repo_dir};
55
use crate::app_state::AppState;
@@ -57,6 +57,7 @@ pub struct ProjectRepoSyncStatusInfo {
5757
pub remote_branch: Option<String>,
5858
pub remote_head: Option<String>,
5959
pub remote_short_head: Option<String>,
60+
pub merge_base: Option<String>,
6061
pub ahead_count: usize,
6162
pub behind_count: usize,
6263
pub has_uncommitted_changes: bool,
@@ -70,6 +71,9 @@ pub struct ProjectRepoSyncStatusInfo {
7071
pub struct ProjectRepoPushResult {
7172
pub pushed: bool,
7273
pub message: String,
74+
pub branch: String,
75+
pub commit: String,
76+
pub merge_base: Option<String>,
7377
}
7478
#[derive(Serialize)]
7579
pub struct ProjectRepoPullResult {
@@ -104,7 +108,7 @@ fn short_hash(hash: &str) -> String {
104108
hash.chars().take(7).collect()
105109
}
106110

107-
fn first_output_line(output: &str) -> Option<String> {
111+
pub(crate) fn first_output_line(output: &str) -> Option<String> {
108112
output
109113
.lines()
110114
.next()
@@ -492,6 +496,7 @@ fn compare_local_remote_status(
492496
repo_dir: &std::path::Path,
493497
clone_url: &str,
494498
branch_name: Option<&str>,
499+
base_branch: Option<&str>,
495500
auth: &GitAuthConfig,
496501
) -> ProjectRepoSyncStatusInfo {
497502
let local_branch = run_git(&["branch", "--show-current"], Some(repo_dir), auth)
@@ -518,18 +523,20 @@ fn compare_local_remote_status(
518523
auth,
519524
);
520525
}
521-
let _ = run_git(
522-
&[
523-
"fetch",
524-
"--quiet",
525-
"--depth=100",
526-
"--end-of-options",
527-
"origin",
528-
branch.as_str(),
529-
],
530-
Some(repo_dir),
531-
auth,
532-
);
526+
let base_branch =
527+
normalize_branch_option(base_branch).filter(|base_branch| *base_branch != branch);
528+
let mut fetch_args = vec![
529+
"fetch",
530+
"--quiet",
531+
"--depth=100",
532+
"--end-of-options",
533+
"origin",
534+
branch.as_str(),
535+
];
536+
if let Some(base_branch) = base_branch.as_deref() {
537+
fetch_args.push(base_branch);
538+
}
539+
let _ = run_git(&fetch_args, Some(repo_dir), auth);
533540

534541
let local_head = run_git(&["rev-parse", "HEAD"], Some(repo_dir), auth)
535542
.ok()
@@ -542,6 +549,19 @@ fn compare_local_remote_status(
542549
)
543550
.ok()
544551
.and_then(|output| first_output_line(&output));
552+
let merge_base = base_branch.as_deref().and_then(|base_branch| {
553+
run_git(
554+
&[
555+
"merge-base",
556+
"HEAD",
557+
format!("origin/{base_branch}").as_str(),
558+
],
559+
Some(repo_dir),
560+
auth,
561+
)
562+
.ok()
563+
.and_then(|output| first_output_line(&output))
564+
});
545565
let status = run_git(&["status", "--porcelain"], Some(repo_dir), auth).unwrap_or_default();
546566
let has_uncommitted_changes = has_uncommitted_changes(&status);
547567
let has_untracked_files = has_untracked_files(&status);
@@ -576,6 +596,10 @@ fn compare_local_remote_status(
576596

577597
let push_block_reason = if local_head.is_none() {
578598
Some("No local commits to push.".to_string())
599+
} else if local_branch.as_deref() != Some(branch.as_str()) {
600+
Some(format!(
601+
"Local checkout is on a different branch than {branch}."
602+
))
579603
} else if has_uncommitted_changes || has_untracked_files {
580604
Some("Commit or discard local changes before pushing.".to_string())
581605
} else if behind_count > 0 {
@@ -615,6 +639,7 @@ fn compare_local_remote_status(
615639
remote_branch: Some(branch),
616640
remote_head: remote_head.clone(),
617641
remote_short_head: remote_head.as_deref().map(short_hash),
642+
merge_base,
618643
ahead_count,
619644
behind_count,
620645
has_uncommitted_changes,
@@ -657,7 +682,7 @@ pub async fn get_project_repo_snapshot(
657682
target_commit: Option<String>,
658683
state: State<'_, AppState>,
659684
) -> Result<ProjectRepoSnapshotInfo, String> {
660-
validate_clone_url(&clone_url)?;
685+
validate_workspace_clone_url(&clone_url, &state)?;
661686
let auth = build_git_auth_config(&state)?;
662687
let branch = clean_branch(default_branch);
663688
let base_branch = clean_branch(base_branch);
@@ -793,10 +818,11 @@ pub async fn get_project_repo_sync_status(
793818
repos_dir: Option<String>,
794819
project_dtag: String,
795820
clone_url: String,
796-
default_branch: Option<String>,
821+
branch_name: Option<String>,
822+
base_branch: Option<String>,
797823
state: State<'_, AppState>,
798824
) -> Result<ProjectRepoSyncStatusInfo, String> {
799-
validate_clone_url(&clone_url)?;
825+
validate_workspace_clone_url(&clone_url, &state)?;
800826
let auth = build_git_auth_config(&state)?;
801827

802828
tauri::async_runtime::spawn_blocking(move || {
@@ -808,11 +834,12 @@ pub async fn get_project_repo_sync_status(
808834
local_branch: None,
809835
local_head: None,
810836
local_short_head: None,
811-
remote_branch: default_branch
837+
remote_branch: branch_name
812838
.as_deref()
813839
.and_then(|branch| normalize_branch_option(Some(branch))),
814840
remote_head: None,
815841
remote_short_head: None,
842+
merge_base: None,
816843
ahead_count: 0,
817844
behind_count: 0,
818845
has_uncommitted_changes: false,
@@ -827,7 +854,8 @@ pub async fn get_project_repo_sync_status(
827854
Ok(compare_local_remote_status(
828855
&repo_dir,
829856
&clone_url,
830-
default_branch.as_deref(),
857+
branch_name.as_deref(),
858+
base_branch.as_deref(),
831859
&auth,
832860
))
833861
})
@@ -840,10 +868,11 @@ pub async fn push_project_local_repository(
840868
repos_dir: Option<String>,
841869
project_dtag: String,
842870
clone_url: String,
843-
default_branch: Option<String>,
871+
branch_name: Option<String>,
872+
base_branch: Option<String>,
844873
state: State<'_, AppState>,
845874
) -> Result<ProjectRepoPushResult, String> {
846-
validate_clone_url(&clone_url)?;
875+
validate_workspace_clone_url(&clone_url, &state)?;
847876
let auth = build_git_auth_config(&state)?;
848877

849878
tauri::async_runtime::spawn_blocking(move || {
@@ -852,17 +881,26 @@ pub async fn push_project_local_repository(
852881
else {
853882
return Err("No local checkout found.".to_string());
854883
};
855-
let status =
856-
compare_local_remote_status(&repo_dir, &clone_url, default_branch.as_deref(), &auth);
884+
let status = compare_local_remote_status(
885+
&repo_dir,
886+
&clone_url,
887+
branch_name.as_deref(),
888+
base_branch.as_deref(),
889+
&auth,
890+
);
857891
if !status.can_push {
858892
return Err(status
859893
.push_block_reason
860894
.unwrap_or_else(|| "Local checkout cannot be pushed.".to_string()));
861895
}
862896
let branch = status
863897
.remote_branch
864-
.as_deref()
898+
.clone()
865899
.ok_or_else(|| "No branch selected for push.".to_string())?;
900+
let commit = status
901+
.local_head
902+
.clone()
903+
.ok_or_else(|| "No local commit selected for push.".to_string())?;
866904
run_git(
867905
&[
868906
"push",
@@ -877,6 +915,9 @@ pub async fn push_project_local_repository(
877915
Ok(ProjectRepoPushResult {
878916
pushed: true,
879917
message: format!("Pushed {branch} to remote."),
918+
branch,
919+
commit,
920+
merge_base: status.merge_base,
880921
})
881922
})
882923
.await
@@ -890,10 +931,10 @@ pub async fn pull_project_local_repository(
890931
repos_dir: Option<String>,
891932
project_dtag: String,
892933
clone_url: String,
893-
default_branch: Option<String>,
934+
branch_name: Option<String>,
894935
state: State<'_, AppState>,
895936
) -> Result<ProjectRepoPullResult, String> {
896-
validate_clone_url(&clone_url)?;
937+
validate_workspace_clone_url(&clone_url, &state)?;
897938
let auth = build_git_auth_config(&state)?;
898939

899940
tauri::async_runtime::spawn_blocking(move || {
@@ -903,7 +944,7 @@ pub async fn pull_project_local_repository(
903944
return Err("No local checkout found.".to_string());
904945
};
905946
let status =
906-
compare_local_remote_status(&repo_dir, &clone_url, default_branch.as_deref(), &auth);
947+
compare_local_remote_status(&repo_dir, &clone_url, branch_name.as_deref(), None, &auth);
907948
if !status.can_pull {
908949
return Err(status
909950
.pull_block_reason

‎desktop/src-tauri/src/commands/project_git_diff.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::project_git_exec::{
2-
build_git_auth_config, clean_branch, run_git, validate_clone_url, GitAuthConfig,
2+
build_git_auth_config, clean_branch, run_git, validate_workspace_clone_url, GitAuthConfig,
33
};
44
use super::project_repo_paths::find_local_repo_dir;
55
use crate::app_state::AppState;
@@ -37,7 +37,7 @@ fn clean_target_ref(value: Option<String>) -> Option<String> {
3737
})
3838
}
3939

40-
fn clean_commit(value: Option<String>) -> Option<String> {
40+
pub(crate) fn clean_commit(value: Option<String>) -> Option<String> {
4141
value
4242
.filter(|value| matches!(value.len(), 40 | 64))
4343
.filter(|value| value.chars().all(|c| c.is_ascii_hexdigit()))
@@ -388,7 +388,7 @@ pub async fn get_project_repo_diff(
388388
target_commit: Option<String>,
389389
state: State<'_, AppState>,
390390
) -> Result<ProjectRepoDiffInfo, String> {
391-
validate_clone_url(&clone_url)?;
391+
validate_workspace_clone_url(&clone_url, &state)?;
392392
let auth = build_git_auth_config(&state)?;
393393
let branch = clean_branch(default_branch);
394394
let base_branch = clean_branch(base_branch);

0 commit comments

Comments
 (0)