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

Look at the current reviewRef when submitting #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iveqy
Copy link

@iveqy iveqy commented Jul 20, 2022

When a review has been rebased and then force pushed to update a review,
for example to fix review comments. It can become impossible to submit
with the error message:

Refusing to submit a non-fast-forward review. First merge the target
ref.

this even if the review ref is a ancestor of the target ref and the
merge should been a fast forward merge. This is because the check for
appraise submit is done against the first commit sha1 that was used and
not for the actually reviewRef that will be merged. This fixes that.

When a review has been rebased and then force pushed to update a review,
for example to fix review comments. It can become impossible to submit
with the error message:

Refusing to submit a non-fast-forward review. First merge the target
ref.

this even if the review ref is a ancestor of the target ref and the
merge should been a fast forward merge. This is because the check for
appraise submit is done against the first commit sha1 that was used and
not for the actually reviewRef that will be merged. This fixes that.
@google-cla
Copy link

google-cla bot commented Jul 20, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@iveqy
Copy link
Author

iveqy commented Jul 20, 2022

For some reason this mess up the git-appraise list view where submitted code reviews will still be shown as open. IT tells me that there's more to this than just this merge request.

@ojarjur
Copy link
Collaborator

ojarjur commented Aug 10, 2022

Hi @iveqy, thanks for taking the time and putting in the effort to contribute to the tool.

As you noted, there is more to what is going on than just the IsAncestor check.

When you rebase the commits in a review outside of using the git appraise rebase command, then we lose any link between the original commit and the commit you are trying to submit.

That means that even if we disabled the IsAncestor check, the original review would not show up as being submitted, because git-appraise does not know the commits are related.

This can be fixed by running git appraise rebase prior to running git appraise submit, so maybe instead all we need to do is catch this scenario and give the user appropriate instructions.

I'll add an inline comment giving an example of what I am thinking.

@@ -78,8 +78,8 @@ func submitReview(repo repository.Repo, args []string) error {
if err := repo.VerifyGitRef(target); err != nil {
return err
}
source, err := r.GetHeadCommit()
if err != nil {
source := r.Request.ReviewRef
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still want to use the result of GetHeadCommit in the below check. It will actually use the review ref head if the metadata linking the review commit to the review ref head is properly set up.

However, we also want to give the user instructions on how to fix it if that metadata is not correct.

I think a better fix might be to add logic right after this (right before we check the ancestry of the target ref) to double check that the metadata is correct and give the user instructions on how to fix it if it is not.

Something like:

	isReviewAssociatedWithRef, err := repo.IsAncestor(source, r.Request.ReviewRef)
	if err != nil {
		return err
	}
	if !isReviewAssociatedWithRef {
		return fmt.Errorf("The review commit is not associated with the review ref %q. If the change has been rebased, then reassociate the review commit with the review ref using the command `git appraise rebase %s`", r.Request.ReviewRef, r.Revision)
	}

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.

2 participants