8000 Tidy up naming in `SyncToParentStatus` by PawelLipski · Pull Request #1390 · VirtusLab/git-machete · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Tidy up naming in SyncToParentStatus #1390

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

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions git_machete/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@


class SyncToParentStatus(Enum):
InSync = auto()
MergedToParent = auto()
InSyncButForkPointOff = auto()
OutOfSync = auto()
IN_SYNC = auto()
IN_SYNC_BUT_FORK_POINT_OFF = auto()
OUT_OF_SYNC = auto()
MERGED_TO_PARENT = auto()


sync_to_parent_status_to_edge_color_map: Dict[SyncToParentStatus, str] = {
SyncToParentStatus.MergedToParent: AnsiEscapeCodes.DIM,
SyncToParentStatus.InSync: AnsiEscapeCodes.GREEN,
SyncToParentStatus.InSyncButForkPointOff: AnsiEscapeCodes.YELLOW,
SyncToParentStatus.OutOfSync: AnsiEscapeCodes.RED
SyncToParentStatus.IN_SYNC: AnsiEscapeCodes.GREEN,
SyncToParentStatus.IN_SYNC_BUT_FORK_POINT_OFF: AnsiEscapeCodes.YELLOW,
SyncToParentStatus.OUT_OF_SYNC: AnsiEscapeCodes.RED,
SyncToParentStatus.MERGED_TO_PARENT: AnsiEscapeCodes.DIM
}

sync_to_parent_status_to_junction_ascii_only_map: Dict[SyncToParentStatus, str] = {
SyncToParentStatus.MergedToParent: "m-",
SyncToParentStatus.InSync: "o-",
SyncToParentStatus.InSyncButForkPointOff: "?-",
SyncToParentStatus.OutOfSync: "x-"
SyncToParentStatus.IN_SYNC: "o-",
SyncToParentStatus.IN_SYNC_BUT_FORK_POINT_OFF: "?-",
SyncToParentStatus.OUT_OF_SYNC: "x-",
SyncToParentStatus.MERGED_TO_PARENT: "m-"
}

E = TypeVar('E', bound='Enum')
Expand Down Expand Up @@ -1161,14 +1161,14 @@ def fork_point_hash(branch_: LocalBranchShortName) -> Optional[FullCommitHash]:
branch=branch,
upstream=parent_branch,
opt_squash_merge_detection=opt_squash_merge_detection):
sync_to_parent_status[branch] = SyncToParentStatus.MergedToParent
sync_to_parent_status[branch] = SyncToParentStatus.MERGED_TO_PARENT
elif not self.__git.is_ancestor_or_equal(parent_branch.full_name(), branch.full_name()):
sync_to_parent_status[branch] = SyncToParentStatus.OutOfSync
sync_to_parent_status[branch] = SyncToParentStatus.OUT_OF_SYNC
elif self.__get_overridden_fork_point(branch) or \
self.__git.get_commit_hash_by_revision(parent_branch) == fork_point_hash(branch):
sync_to_parent_status[branch] = SyncToParentStatus.InSync
sync_to_parent_status[branch] = SyncToParentStatus.IN_SYNC
else:
sync_to_parent_status[branch] = SyncToParentStatus.InSyncButForkPointOff
sync_to_parent_status[branch] = SyncToParentStatus.IN_SYNC_BUT_FORK_POINT_OFF

currently_rebased_branch = self.__git.get_currently_rebased_branch_or_none()
currently_checked_out_branch = self.__git.get_currently_checked_out_branch_or_none()
Expand Down Expand Up @@ -1198,9 +1198,9 @@ def print_line_prefix(branch_: LocalBranchShortName, suffix: str) -> None:
if not fork_point:
# Rare case, but can happen e.g. due to reflog expiry.
commits: List[GitLogEntry] = []
elif sync_to_parent_status[branch] == SyncToParentStatus.MergedToParent:
elif sync_to_parent_status[branch] == SyncToParentStatus.MERGED_TO_PARENT:
commits = []
elif sync_to_parent_status[branch] == SyncToParentStatus.InSyncButForkPointOff:
elif sync_to_parent_status[branch] == SyncToParentStatus.IN_SYNC_BUT_FORK_POINT_OFF:
upstream = self.__up_branch[branch]
assert upstream is not None
commits = self.__git.get_commits_between(upstream.full_name(), branch.full_name())
Expand Down Expand Up @@ -1269,7 +1269,8 @@ def print_line_prefix(branch_: LocalBranchShortName, suffix: str) -> None:
s, remote = self.__git.get_combined_remote_sync_status(branch)
sync_status = {
SyncToRemoteStatus.NO_REMOTES: "",
SyncToRemoteStatus.UNTRACKED: colored(" (untracked)", AnsiEscapeCodes.ORANGE),
SyncToRemoteStatus.UNTRACKED:
colored(" (untracked)", AnsiEscapeCodes.ORANGE),
SyncToRemoteStatus.IN_SYNC_WITH_REMOTE: "",
SyncToRemoteStatus.BEHIND_REMOTE:
colored(f" (behind {bold(remote)})", AnsiEscapeCodes.RED), # type: ignore [arg-type]
Expand Down Expand Up @@ -1300,7 +1301,8 @@ def print_line_prefix(branch_: LocalBranchShortName, suffix: str) -> None:
sys.stdout.write(out.getvalue())
out.close()

branches_in_sync_but_fork_point_off = [k for k, v in sync_to_parent_status.items() if v == SyncToParentStatus.InSyncButForkPointOff]
branches_in_sync_but_fork_point_off = [k for k, v in sync_to_parent_status.items() if v ==
SyncToParentStatus.IN_SYNC_BUT_FORK_POINT_OFF]
if branches_in_sync_but_fork_point_off and warn_when_branch_in_sync_but_fork_point_off:
yellow_edge_branch: LocalBranchShortName = branches_in_sync_but_fork_point_off[0]
if len(branches_in_sync_but_fork_point_off) == 1:
Expand Down Expand Up @@ -3207,7 +3209,7 @@ def delete_untracked(self, opt_yes: bool) -> None:
def slide_out_removed_from_remote(self, opt_delete: bool) -> None:
slid_out_branches: List[LocalBranchShortName] = []
for branch in self.managed_branches.copy():
if self.__git.is_missing_tracking_branch(branch) and not self.__down_branches.get(branch):
if self.__git.is_removed_from_remote(branch) and not self.__down_branches.get(branch):
print(fmt(f"Sliding out <b>{branch}</b>"))
slid_out_branches.append(branch)

Expand Down
16 changes: 8 additions & 8 deletions git_machete/git_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ def __init__(self) -> None:
self.__is_equivalent_tree_reachable_cached: Dict[Tuple[FullCommitHash, FullCommitHash], bool] = {}
self.__local_branches_cached: Optional[List[LocalBranchShortName]] = None
self.__merge_base_cached: Dict[Tuple[FullCommitHash, FullCommitHash], Optional[FullCommitHash]] = {}
self.__missing_tracking_branch: Optional[Set[str]] = None
self.__reflogs_cached: Optional[Dict[AnyBranchName, List[GitReflogEntry]]] = None
self.__remaining_log_hashes_cached: Dict[FullCommitHash, List[FullCommitHash]] = {}
self.__remote_branches_cached: Optional[List[RemoteBranchShortName]] = None
self.__remotes_cached: Optional[List[str]] = None
self.__removed_from_remote: Optional[Set[str]] = None
self.__short_commit_hash_by_revision_cached: Dict[AnyRevision, Optional[ShortCommitHash]] = {}
self.__tree_hash_by_commit_hash_cached: Optional[Dict[FullCommitHash, Optional[FullTreeHash]]] = None

Expand All @@ -249,10 +249,10 @@ def flush_caches(self) -> None:
self.__config_cached = None
self.__counterparts_for_fetching_cached = None
self.__local_branches_cached = None
self.__missing_tracking_branch = None
self.__reflogs_cached = None
self.__remote_branches_cached = None
self.__remotes_cached = None
self.__removed_from_remote = None
self.__short_commit_hash_by_revision_cached = {}

def _run_git(self, git_cmd: str, *args: str, flush_caches: bool, allow_non_zero: bool = False) -> int:
Expand Down Expand Up @@ -537,11 +537,11 @@ def get_combined_counterpart_for_fetching_of_branch(self, branch: LocalBranchSho
# we try to infer the remote if the tracking data is missing.
return self.get_strict_counterpart_for_fetching_of_branch(branch) or self.__get_inferred_counterpart_for_fetching_of_branch(branch)

def is_missing_tracking_branch(self, branch: LocalBranchShortName) -> bool:
if self.__missing_tracking_branch is None:
def is_removed_from_remote(self, branch: LocalBranchShortName) -> bool:
if self.__removed_from_remote is None:
self.__load_branches()
assert self.__missing_tracking_branch is not None
return branch in self.__missing_tracking_branch
assert self.__removed_from_remote is not None
return branch in self.__removed_from_remote

# Note that rebase/cherry-pick/merge/revert all happen on per-worktree basis,
# so we need to check .git/worktrees/<worktree>/<file> rather than .git/<file>
Expand Down Expand Up @@ -579,7 +579,7 @@ def __load_branches(self) -> None:
self.__committer_unix_timestamp_by_revision_cached = {}
self.__counterparts_for_fetching_cached = {}
self.__local_branches_cached = []
self.__missing_tracking_branch = set()
self.__removed_from_remote = set()
self.__remote_branches_cached = []
self.__tree_hash_by_commit_hash_cached = {}

Expand Down Expand Up @@ -626,7 +626,7 @@ def __load_branches(self) -> None:
if fetch_counterpart_stripped in self.__remote_branches_cached:
self.__counterparts_for_fetching_cached[b_stripped_local] = fetch_counterpart_stripped
elif fetch_counterpart_stripped is not None:
self.__missing_tracking_branch.add(b_stripped_local)
self.__removed_from_remote.add(b_stripped_local)

def __get_log_hashes(self, revision: AnyRevision, max_count: Optional[int]) -> List[FullCommitHash]:
opts = ([f"--max-count={str(max_count)}"] if max_count else []) + ["--format=%H", revision.full_name()]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,16 @@ def test_status_no_fork_point_for_child_branch(self) -> None:
x-develop *
"""
)

def test_status_removed_from_remote(self) -> None:
(
self.repo_sandbox.new_branch('main')
.commit()
.push()
.delete_remote_branch('origin/main')
)
rewrite_branch_layout_file("main")
assert_success(
["status"],
"main * (untracked)\n"
)
0