Skip to content

Add check against main branch hook #1400

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Lee-W
Copy link
Member

@Lee-W Lee-W commented May 6, 2025

Description

Checklist

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

Steps to Test This Pull Request

Additional context

Copy link

codecov bot commented May 6, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 97.40%. Comparing base (120d514) to head (5fafc37).
Report is 592 commits behind head on master.

Files with missing lines Patch % Lines
commitizen/git.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1400      +/-   ##
==========================================
+ Coverage   97.33%   97.40%   +0.06%     
==========================================
  Files          42       57      +15     
  Lines        2104     2661     +557     
==========================================
+ Hits         2048     2592     +544     
- Misses         56       69      +13     
Flag Coverage Δ
unittests 97.40% <66.66%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.



def guess_default_branch() -> str:
c = cmd.run("git branch --format '%(refname:short)' --list master main")
Copy link
Member

Choose a reason for hiding this comment

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

This makes a strong hypothesis that the reference branch can only be master or main so it won't work with develop which is common, or any other "exotic choice".

To handle this, I use git branch -r | grep -Po "HEAD -> .+/\K.+$" | head -n 1 which works with any default branch as long as there is a remote with a default. The head is for the case where there are multiple remotes, but makes the hypothesis that they share the same default branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I'll have to try those commands 👀 Looks interesting!

I'm thinking of letting users set default_git_remote and default_git_branch_name (but not yet have time to impletemtn it 🥲)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's a good idea. Having guess the default but keeping the possibility to explicitly set it from the configuration 👍🏼

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

Successfully merging this pull request may close these issues.

2 participants