MCPcopy Create free account
hub / github.com/GCWing/BitFun / git_get_repository

Function git_get_repository

src/apps/desktop/src/api/git_api.rs:537–596  ·  view source on GitHub ↗
(
    state: State<'_, AppState>,
    request: GitRepositoryRequest,
)

Source from the content-addressed store, hash-verified

535
536#[tauri::command]
537pub async fn git_get_repository(
538 state: State<'_, AppState>,
539 request: GitRepositoryRequest,
540) -> Result<GitRepository, String> {
541 if let Some(target) = resolve_remote_git_target(&request.repository_path).await {
542 let current_branch = execute_remote_git_success(
543 &state,
544 &target,
545 &["branch".to_string(), "--show-current".to_string()],
546 )
547 .await
548 .map(|s| {
549 let branch = s.trim();
550 if branch.is_empty() {
551 "HEAD".to_string()
552 } else {
553 branch.to_string()
554 }
555 })?;
556 let remotes_output =
557 execute_remote_git_success(&state, &target, &["remote".to_string()]).await?;
558 let status = execute_remote_git_success(
559 &state,
560 &target,
561 &["status".to_string(), "--porcelain".to_string()],
562 )
563 .await?;
564
565 let name = target
566 .repository_path
567 .rsplit('/')
568 .find(|part| !part.is_empty())
569 .unwrap_or("/")
570 .to_string();
571
572 return Ok(GitRepository {
573 path: target.repository_path,
574 name,
575 current_branch,
576 is_bare: false,
577 has_changes: !status.trim().is_empty(),
578 remotes: remotes_output
579 .lines()
580 .map(str::trim)
581 .filter(|s| !s.is_empty())
582 .map(str::to_string)
583 .collect(),
584 });
585 }
586
587 GitService::get_repository(&request.repository_path)
588 .await
589 .map_err(|e| {
590 error!(
591 "Failed to get Git repository info: path={}, error={}",
592 request.repository_path, e
593 );
594 format!("Failed to get Git repository info: {}", e)

Callers

nothing calls this directly

Calls 5

trimMethod · 0.80
collectMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected