-
-
Notifications
You must be signed in to change notification settings - Fork 278
feat: Make cz bump
work on shallow clones
#649
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
Open
robertschweizer
wants to merge
1
commit into
commitizen-tools:master
Choose a base branch
from
robertschweizer:fetch-missing-tags-if-shallow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import inspect | ||
import os | ||
import re | ||
import sys | ||
from pathlib import Path | ||
from typing import Tuple | ||
from unittest.mock import MagicMock | ||
|
||
|
@@ -377,6 +380,32 @@ def test_bump_major_version_zero_when_major_is_not_zero(mocker, tmp_commitizen_p | |
assert expected_error_message in str(excinfo.value) | ||
|
||
|
||
def test_bump_shallow_clone( | ||
tmp_commitizen_project, | ||
tmp_path: Path, | ||
mocker: MockFixture, | ||
capsys: pytest.CaptureFixture, | ||
): | ||
# Set up repository with one released and one unreleased commit. | ||
create_file_and_commit("feat: Add file for 0.1.0") | ||
create_tag("0.1.0") | ||
create_file_and_commit("feat: Add file for, but do not release 0.2.0") | ||
|
||
# Shallow clone this local repository, so the release tag is missing. | ||
cloned_repo = tmp_path / "cloned_repo" | ||
# Use file:// URL, so Git does a shallow clone. | ||
cmd.run(f"git clone --depth=1 file://{tmp_commitizen_project} {cloned_repo}") | ||
os.chdir(cloned_repo) | ||
|
||
# Bumping should work, but with a warning that we are pulling the tag from remote. | ||
testargs = ["cz", "bump"] | ||
mocker.patch.object(sys, "argv", testargs) | ||
capsys.readouterr() # Reset capsys fixture | ||
cli.main() | ||
stdout, _stderr = capsys.readouterr() | ||
assert re.search("Could not find tag.*trying to fetch", stdout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also check whether the function returns correctly after fetching? |
||
|
||
|
||
def test_bump_files_only(mocker: MockFixture, tmp_commitizen_project): | ||
tmp_version_file = tmp_commitizen_project.join("__version__.py") | ||
tmp_version_file.write("0.1.0") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this functionality. But one of the concerns I have is whether this is an unexpected action from the user point of view. I'm thinking of using a flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this is more CI configuration, is up to the user, I'm fine with a warning and an explanation with the next steps to the user. But the user should ensure the environment (git) is providing commitizen what's needed, not the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reviews!
I agree with your concerns that auto-fetching missing tags is unexpected from the user point of view. Actually it would be cleanest to me if
git tag --list {tag}
had a flag to do this fetching for shallow clones automatically. But without auto-fetching missing tags in shallow clones, the only option would be to do a full clone, which can be quite slow for large/old repositories.I believe both Gitlab CI and Github Actions use shallow clones by default. Because of that, Commitizen should ideally handle shallow clones out-of-the-box without setting an extra flag. Do you have examples which workflows could break if we fetch in shallow clones by default? I'm mostly worried about connection issues/the CI not setting up the Git remote for later fetching.
If you keep not being convinced, should we call the flag
--auto-fetch
and only add it for thecz bump
command for now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @robertschweizer Sorry for late reply. I like the idea of the flag
--auto-fetch
. @woile What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a flag and a setting. We can prompt the user in the init command