-
Notifications
You must be signed in to change notification settings - Fork 0
Allow creating kindra temp worktrees #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,62 @@ pub fn branch_status_for_directory(path: &Path) -> Option<(GitBranchSync, bool)> | |
| Some((sync, dirty)) | ||
| } | ||
|
|
||
| /// Resolves the trunk branch name (e.g. `main` or `master`) for a repository. | ||
| /// | ||
| /// Prefers the remote's default branch (`origin/HEAD`), then falls back to a | ||
| /// local `main`/`master`, and finally defaults to `main` so callers always have | ||
| /// a usable start point. | ||
| pub fn trunk_branch(repo_root: &Path) -> String { | ||
| if let Some(branch) = remote_default_branch(repo_root) { | ||
| return branch; | ||
| } | ||
|
|
||
| for candidate in ["main", "master"] { | ||
| if local_branch_exists(repo_root, candidate) { | ||
| return candidate.to_string(); | ||
| } | ||
| } | ||
|
|
||
| "main".to_string() | ||
| } | ||
|
|
||
| fn remote_default_branch(repo_root: &Path) -> Option<String> { | ||
| let output = Command::new("git") | ||
| .current_dir(repo_root) | ||
| .args(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"]) | ||
| .output() | ||
| .ok()?; | ||
| if !output.status.success() { | ||
| return None; | ||
| } | ||
|
|
||
| let raw = String::from_utf8_lossy(&output.stdout); | ||
| let trimmed = raw.trim(); | ||
| // `origin/main` -> `main` | ||
| let branch = trimmed.strip_prefix("origin/").unwrap_or(trimmed); | ||
| if branch.is_empty() { | ||
| None | ||
| } else { | ||
| Some(branch.to_string()) | ||
| } | ||
| } | ||
|
|
||
| fn local_branch_exists(repo_root: &Path, branch: &str) -> bool { | ||
| // Capture output rather than inheriting the terminal: `status()` would let any | ||
| // git warning/hint leak onto the raw-mode picker and corrupt the display. | ||
| Command::new("git") | ||
| .current_dir(repo_root) | ||
| .args([ | ||
| "show-ref", | ||
| "--verify", | ||
| "--quiet", | ||
| &format!("refs/heads/{branch}"), | ||
| ]) | ||
| .output() | ||
| .map(|output| output.status.success()) | ||
| .unwrap_or(false) | ||
| } | ||
|
Comment on lines
+199
to
+234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift No timeout on
🤖 Prompt for AI Agents |
||
|
|
||
| /// Gets the git repository root based on the current tmux state. | ||
| /// Finds the current session's focused window path and resolves it to a git repo root. | ||
| pub fn worktree_repo_root(state: &DomainState, client_id: Option<&str>) -> Option<PathBuf> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.