MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / resolve_branch_commit

Function resolve_branch_commit

src/git_operations.rs:555–572  ·  view source on GitHub ↗

Resolves a local branch name to its commit SHA. Validates that the branch exists as a local branch (via `refs/heads/ `) and returns the commit SHA it points to. # Errors Returns an error if the branch does not exist locally, with a hint about creating a local tracking branch.

(repo_path: &Path, branch: &str)

Source from the content-addressed store, hash-verified

553/// Returns an error if the branch does not exist locally, with a hint
554/// about creating a local tracking branch.
555pub async fn resolve_branch_commit(repo_path: &Path, branch: &str) -> Result<String, String> {
556 let ref_name = format!("refs/heads/{branch}");
557 let output = tokio::process::Command::new("git")
558 .args(["rev-parse", "--verify", &ref_name])
559 .current_dir(repo_path)
560 .output()
561 .await
562 .map_err(|e| format!("Failed to run git rev-parse: {e}"))?;
563
564 if output.status.success() {
565 Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
566 } else {
567 Err(format!(
568 "Branch '{branch}' not found. Make sure it exists as a local branch.\n\
569 To create a local tracking branch: git checkout -b {branch} origin/{branch}"
570 ))
571 }
572}
573
574/// Get the current branch name
575///

Callers 2

buildMethod · 0.85

Calls 1

successMethod · 0.80

Tested by 1