Skip to content

Conversation

@TomasTomecek
Copy link
Member

...and halt if nothing is staged

I orginally wanted to fix a case so a rebase agent reuses MRs but realized it's already done.

We have two equal rebases here !17, !16 because of a bug fixed in b4017b0

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds a check to prevent creating an empty commit by verifying if there are any staged files. The logic is sound. I've included one suggestion to improve the efficiency of this check by using the exit code from git diff rather than processing its standard output.

@TomasTomecek
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a useful pre-commit check to ensure there are staged changes, preventing empty commits. The logic correctly uses git diff --cached --quiet and halts execution if no files are staged. The addition of a docstring to the run_subprocess function is also a good improvement for code clarity. My review includes one suggestion to make a comment more descriptive, which will improve long-term maintainability.

["git", "diff", "--cached", "--quiet"],
cwd=local_clone,
)
# 1 = staged, 0 = none staged
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This comment is a bit terse and might be unclear to developers not familiar with the exit codes of git diff. For better readability and maintainability, I suggest making the comment more descriptive.

Suggested change
# 1 = staged, 0 = none staged
# `git diff --cached --quiet` exits with 1 if there are staged changes, and 0 if there are none.

Copy link
Member Author

Choose a reason for hiding this comment

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

that's literally what my comment says, everyone will easily get it; darling you are just picking nits

# 1 = staged, 0 = none staged
if exit_code == 0:
logger.info("No files staged for commit, halting.")
return "No files staged for commit, halting."
Copy link
Member

Choose a reason for hiding this comment

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

We should probably raise an exception here, this will not halt the process, it will let it continue with MR URL set to that text 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure? If we return here, no commit/push/create-mr would happen.

In the workflow I can see that the next step is to comment in Jira, so I expect the agent to set the status to "failed" or something.

Copy link
Member

Choose a reason for hiding this comment

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

Why would it set status to failed? There is no such logic in the code. It will succeed with merge_request_url: No files staged for commit, halting..

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, I can see it now

...and halt if nothing is staged

Signed-off-by: Tomas Tomecek <[email protected]>
Assisted-by: Cursor(Claude)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@TomasTomecek
Copy link
Member Author

/gemini review

available_tools=gateway_tools,
commit_only=dry_run,
)
except Exception as e:
Copy link
Member Author

Choose a reason for hiding this comment

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

Gemini, I know you will not like this but sweetie you need to get over it

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a useful check to prevent empty git commits by verifying if there are any staged files before the commit operation. If no files are staged, it correctly raises a RuntimeError. This exception is then handled gracefully in both backport_agent.py and rebase_agent.py by wrapping the call in a try...except block, which logs the error and updates the state accordingly. This improves the robustness of the agents. My review includes a minor suggestion to improve a code comment for better clarity.

@TomasTomecek TomasTomecek merged commit 7cd29d3 into packit:main Sep 8, 2025
4 checks passed
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