fix: workspaces rm #2
1 changed files with 10 additions and 19 deletions
|
|
@ -644,40 +644,31 @@ def find_repo_for_worktree(
|
||||||
|
|
||||||
def has_unpushed_commits(repo_path: Path, branch: str) -> bool:
|
def has_unpushed_commits(repo_path: Path, branch: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Detect if `branch` has commits not on its upstream.
|
Detect if branch has commits not on its upstream.
|
||||||
|
Uses 'git rev-list @{u}..HEAD'; if non-empty, there are unpushed commits.
|
||||||
If no upstream is configured, we *do not* treat that as "unpushed" anymore,
|
|
||||||
just "can't check", and return False (so rm won't block on it).
|
|
||||||
"""
|
"""
|
||||||
# Find upstream ref, e.g. origin/branch
|
# Check if upstream exists
|
||||||
code, out, _ = run_cmd(
|
code, _, _ = run_cmd(
|
||||||
["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"],
|
["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"],
|
||||||
cwd=repo_path,
|
cwd=repo_path,
|
||||||
)
|
)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
# No upstream configured; assume "not able to check", *not* a blocker.
|
# No upstream configured; treat as unpushed work.
|
||||||
return False
|
return True
|
||||||
|
|
||||||
upstream = out.strip()
|
|
||||||
if not upstream or upstream == "@{u}":
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Number of commits on HEAD that are not in upstream
|
|
||||||
code, out, _ = run_cmd(
|
code, out, _ = run_cmd(
|
||||||
["git", "rev-list", "--count", f"{upstream}..{branch}"],
|
["git", "rev-list", "@{u}..HEAD", "--count"],
|
||||||
cwd=repo_path,
|
cwd=repo_path,
|
||||||
)
|
)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
# If we can't check, don't block
|
return True
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
count = int(out.strip() or "0")
|
count = int(out.strip() or "0")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return True
|
||||||
|
|
||||||
return count > 0
|
return count > 0
|
||||||
|
|
||||||
|
|
||||||
def is_branch_integrated_into_main(
|
def is_branch_integrated_into_main(
|
||||||
repo_path: Path,
|
repo_path: Path,
|
||||||
branch: str,
|
branch: str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue