generated from coulomb/repo-seed
fix(consistency): correct behind-remote detection to not trigger on local-ahead
_detect_behind_remote was comparing HEAD != @{u} which incorrectly
triggered C-16 when the local repo had unpushed commits. Fixed to use
git rev-list --count HEAD..@{u} which only counts commits the remote
has that local lacks. Adds test_returns_false_when_local_ahead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -450,6 +450,26 @@ class TestDetectBehindRemote:
|
||||
subprocess.run(["git", "-C", str(clone), "push", "origin", "HEAD"], capture_output=True)
|
||||
assert _detect_behind_remote(str(clone)) is False
|
||||
|
||||
def test_returns_false_when_local_ahead(self, tmp_path):
|
||||
"""Local has unpushed commits — NOT considered behind."""
|
||||
import subprocess
|
||||
bare = tmp_path / "bare.git"
|
||||
clone = tmp_path / "clone"
|
||||
bare.mkdir()
|
||||
subprocess.run(["git", "init", "--bare", str(bare)], capture_output=True)
|
||||
subprocess.run(["git", "clone", str(bare), str(clone)], capture_output=True)
|
||||
subprocess.run(
|
||||
["git", "-C", str(clone), "commit", "--allow-empty", "-m", "init"],
|
||||
capture_output=True,
|
||||
)
|
||||
subprocess.run(["git", "-C", str(clone), "push", "origin", "HEAD:main"], capture_output=True)
|
||||
# Add a local-only commit (not pushed)
|
||||
subprocess.run(
|
||||
["git", "-C", str(clone), "commit", "--allow-empty", "-m", "local only"],
|
||||
capture_output=True,
|
||||
)
|
||||
assert _detect_behind_remote(str(clone)) is False
|
||||
|
||||
def test_returns_true_when_behind(self, tmp_path):
|
||||
"""Remote has a commit the clone doesn't → clone is behind."""
|
||||
import subprocess
|
||||
|
||||
Reference in New Issue
Block a user