File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -364,7 +364,7 @@ def _git_parse_inner(
364
364
365
365
if version is None :
366
366
# If 'git git_describe_command' failed, try to get the information otherwise.
367
- tag = config .version_cls ("0.0" )
367
+ tag = config .version_cls (config . fallback_version or "0.0" )
368
368
node = wd .node ()
369
369
if node is None :
370
370
distance = 0
Original file line number Diff line number Diff line change @@ -823,3 +823,31 @@ def test_git_describe_command_init_conflict() -> None:
823
823
git = GitConfiguration (describe_command = "new command" )
824
824
),
825
825
)
826
+
827
+
828
+ def test_git_no_commits_uses_fallback_version (wd : WorkDir ) -> None :
829
+ """Test that when git describe fails (no commits), fallback_version is used instead of 0.0."""
830
+ # Reinitialize as empty repo to remove any existing commits
831
+ wd ("rm -rf .git" )
832
+ wd ("git init" )
833
+ wd (
"git config user.email [email protected] " )
834
+ wd ('git config user.name "a test"' )
835
+
836
+ # Test with fallback_version set - should use the fallback instead of "0.0"
837
+ config = Configuration (fallback_version = "1.2.3" )
838
+ version = git .parse (str (wd .cwd ), config )
839
+
840
+ # Should get a version starting with the fallback version
841
+ assert version is not None
842
+ assert str (version .tag ) == "1.2.3"
843
+ assert version .distance == 0
844
+ assert version .dirty is True # No commits means dirty
845
+
846
+ # Test without fallback_version - should default to "0.0"
847
+ config_no_fallback = Configuration ()
848
+ version_no_fallback = git .parse (str (wd .cwd ), config_no_fallback )
849
+
850
+ assert version_no_fallback is not None
851
+ assert str (version_no_fallback .tag ) == "0.0"
852
+ assert version_no_fallback .distance == 0
853
+ assert version_no_fallback .dirty is True
You can’t perform that action at this time.
0 commit comments