1- import os
21import tempfile
32import subprocess
43from pathlib import Path
@@ -81,41 +80,30 @@ def test_short(self, git_repo):
8180 gv = GitVersion (repo_path = str (git_repo ))
8281 assert len (gv .short ) == 6
8382
84- def test_full (self , git_repo ):
83+ def test_full_on_release_branch (self , git_repo ):
84+ """On a release branch (master), full should equal version."""
8585 gv = GitVersion (repo_path = str (git_repo ))
86+ assert gv .full == gv .version
87+ assert gv .full == "1.0.0.1"
88+
89+ def test_full_on_non_release_branch (self , git_repo ):
90+ """On a non-release branch, full should equal extended (version-short)."""
91+ gv = GitVersion (
92+ repo_path = str (git_repo ),
93+ release_branches = ["main" , "release/*" ],
94+ )
95+ assert gv .full == gv .extended
8696 assert gv .full == f"1.0.0.1-{ gv .short } "
8797
8898 def test_extended_with_build (self , git_repo ):
99+ """Extended always includes commit hash."""
89100 gv = GitVersion (repo_path = str (git_repo ))
90- assert gv .extended == gv .full
91-
92- def test_extended_without_build (self , git_repo ):
93- """When build == 0, extended should equal version."""
94- with tempfile .TemporaryDirectory () as tmpdir :
95- repo = Path (tmpdir )
96- subprocess .run (["git" , "init" ], cwd = repo , capture_output = True , check = True )
97- subprocess .run (
98- ["git" , "config" , "user.email" , "test@test.com" ],
99- cwd = repo , capture_output = True , check = True ,
100- )
101- subprocess .run (
102- ["git" , "config" , "user.name" , "Test" ],
103- cwd = repo , capture_output = True , check = True ,
104- )
105- (repo / "file.txt" ).write_text ("hello" )
106- subprocess .run (["git" , "add" , "." ], cwd = repo , capture_output = True , check = True )
107- subprocess .run (
108- ["git" , "commit" , "-m" , "initial" ],
109- cwd = repo , capture_output = True , check = True ,
110- )
111- subprocess .run (
112- ["git" , "tag" , "v2.0.0" ],
113- cwd = repo , capture_output = True , check = True ,
114- )
101+ assert gv .extended == f"{ gv .version } -{ gv .short } "
115102
116- gv = GitVersion (repo_path = str (repo ))
117- assert gv .build == "0"
118- assert gv .extended == gv .version
103+ def test_extended_always_contains_commit (self , git_repo ):
104+ """Extended always includes version and short commit hash."""
105+ gv = GitVersion (repo_path = str (git_repo ))
106+ assert gv .extended == f"{ gv .version } -{ gv .short } "
119107
120108 def test_commit (self , git_repo ):
121109 gv = GitVersion (repo_path = str (git_repo ))
@@ -135,6 +123,7 @@ def test_env(self, git_repo):
135123 assert env ["TEST_BUILD" ] == "1"
136124 assert env ["TEST_TAG" ] == "v1.0.0"
137125 assert env ["TEST_BRANCH" ] == "master"
126+ assert env ["TEST_FULL" ] == env ["TEST" ] # On release branch, full == version
138127 assert len (env ["TEST_COMMIT" ]) == 40
139128 assert len (env ["TEST_SHORT" ]) == 6
140129
@@ -178,6 +167,46 @@ def test_not_a_git_repo(self):
178167 assert gv .short == ""
179168 assert gv .commit == ""
180169
170+ def test_release_branches_default (self , git_repo ):
171+ """Default release_branches should include default branch and release/*."""
172+ gv = GitVersion (repo_path = str (git_repo ))
173+ branches = gv .release_branches
174+ assert "master" in branches
175+ assert "release/*" in branches
176+ assert len (branches ) == 2
177+
178+ def test_release_branches_custom (self , git_repo ):
179+ """Custom release_branches should be returned as-is."""
180+ gv = GitVersion (
181+ repo_path = str (git_repo ),
182+ release_branches = ["main" , "release/*" , "hotfix/*" ],
183+ )
184+ assert gv .release_branches == ["main" , "release/*" , "hotfix/*" ]
185+
186+ def test_release_branches_single (self , git_repo ):
187+ """Single branch in release_branches list."""
188+ gv = GitVersion (
189+ repo_path = str (git_repo ),
190+ release_branches = ["main" ],
191+ )
192+ assert gv .release_branches == ["main" ]
193+
194+ def test_release_branches_in_env (self , git_repo ):
195+ """release_branches should appear in env output."""
196+ gv = GitVersion (repo_path = str (git_repo ))
197+ env = gv .env (prefix = "TEST" )
198+ assert "TEST_RELEASE_BRANCHES" in env
199+ assert "master" in env ["TEST_RELEASE_BRANCHES" ]
200+ assert "release/*" in env ["TEST_RELEASE_BRANCHES" ]
201+
202+ def test_release_branches_in_str (self , git_repo ):
203+ """release_branches should appear in string representation."""
204+ gv = GitVersion (repo_path = str (git_repo ))
205+ output = str (gv )
206+ assert "Release branches" in output
207+ assert "master" in output
208+ assert "release/*" in output
209+
181210 def test_str (self , git_repo ):
182211 gv = GitVersion (repo_path = str (git_repo ))
183212 output = str (gv )
0 commit comments