Skip to content

Commit 84c678d

Browse files
committed
Check git version for the init call
The -b flag was added in 2.28.0 and using it in older versions will cause an error to be raised, so add the initial branch name conditionally.
1 parent ba8a346 commit 84c678d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmake-init/__main__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import sys
3232
import zipfile
3333

34+
from distutils.version import LooseVersion
35+
3436
__version__ = "0.5.1"
3537

3638
zip = zipfile.ZipFile(os.path.dirname(__file__), "r")
@@ -163,7 +165,14 @@ def write_dir(path, d, zip_path):
163165

164166

165167
def git_init(cwd):
166-
subprocess.run("git init -b master", shell=True, check=True, cwd=cwd)
168+
branch = ""
169+
git_version_out = \
170+
subprocess.run("git --version", shell=True, capture_output=True)
171+
git_version_str = str(git_version_out.stdout[12:], sys.stdout.encoding)
172+
git_version = LooseVersion(git_version_str.rstrip())
173+
if LooseVersion("2.28.0") <= git_version:
174+
branch = " -b master"
175+
subprocess.run(f"git init{branch}", shell=True, check=True, cwd=cwd)
167176
print("""
168177
The project is ready to be used with git. If you are using GitHub, you may
169178
push the project with the following commands from the project directory:

0 commit comments

Comments
 (0)