Skip to content
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

GitSCM: fix default_branch and target_cset bugs (bug 1945697) #219

Merged
merged 10 commits into from
Feb 6, 2025

Conversation

shtrom
Copy link
Member

@shtrom shtrom commented Feb 5, 2025

No description provided.

@shtrom shtrom force-pushed the bug1945697/git-default_branch-push_target branch from 4d56597 to 08d4fea Compare February 5, 2025 03:57
@shtrom shtrom changed the title GitSCM: fix default_branch and target_cset bugs (bug1945697) GitSCM: fix default_branch and target_cset bugs (bug 1945697) Feb 5, 2025
@shtrom shtrom force-pushed the bug1945697/git-default_branch-push_target branch from 7c062f0 to 68054b4 Compare February 6, 2025 01:15
@shtrom shtrom requested a review from cgsheeh February 6, 2025 01:17
Comment on lines +119 to +122
if not push_target:
push_target = self.default_branch

command += [f"HEAD:{push_target}"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essentially pushes HEAD to push_target? I was thinking we could move the appropriate branch to HEAD with git branch <branch> HEAD -f and then git push origin <branch>, but this works too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. All the additional commits have been implicitly added to HEAD. I don't think we even know the work branch name in other places (we could read it out, but it would be no better than using HEAD)

We should already be on the work branch from the update_repo call, but that's the only time we make the switch explicitly, everything after that assumes it's in the right position.

Could be better in theory, and more explicit about the branch to work on, but I think it would add a lot of overhead vs. setting HEAD once, and assuming it is correct (<- famous last words right there.)

@shtrom shtrom merged commit 4220b9a into main Feb 6, 2025
1 check passed
@shtrom shtrom deleted the bug1945697/git-default_branch-push_target branch February 6, 2025 21:10
Copy link
Collaborator

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments, can be addressed in a followup if necessary.

Comment on lines +301 to 304
work_branch = f"lando-{datetime.now().strftime(ISO8601_TIMESTAMP_BASIC)}"
self._git_run(
"checkout", "--force", "-B", branch, f"origin/{branch}", cwd=self.path
"checkout", "--force", "-B", work_branch, target_cset, cwd=self.path
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we clean up after this? Otherwise we will accumulate a bunch of branches that will never be used again.

Copy link
Member Author

@shtrom shtrom Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should.

I initially was thinking that, as we use --prune during the update, we'd purge them. I'm not so sure it is sufficient now, as those work branches don't have upstreams, and therefore will stick around forever.

In practice, it's probably not a big deal, because the pushes are fast-forwards, so we won't have dangling commits just due to old branches pointing to them, they will just point to non-tip commits.

But it would be better to clean the branches up anyway, yeah.

remote_branch = f"origin/{target_cset}"
if self._git_run("branch", "--list", "--remote", remote_branch, cwd=self.path):
# If the branch exists remotely, make sure we get the up-to-date version.
target_cset = remote_branch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why we are going with that target_cset terminology instead of a more git-centric one?

Copy link
Member Author

@shtrom shtrom Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(copying response to correct comment) Weight of history. It's what the standalone HgRepo object was using, and it got into the abstract_scm.

For git I'd use something like base_ref, but the meaning isn't changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants