@@ -1031,7 +1031,7 @@ def init(
1031
1031
object_format : t .Literal ["sha1" , "sha256" ] | None = None ,
1032
1032
branch : str | None = None ,
1033
1033
initial_branch : str | None = None ,
1034
- shared : bool | None = None ,
1034
+ shared : bool | str | None = None ,
1035
1035
quiet : bool | None = None ,
1036
1036
bare : bool | None = None ,
1037
1037
# libvcs special behavior
@@ -1042,60 +1042,100 @@ def init(
1042
1042
1043
1043
Parameters
1044
1044
----------
1045
- quiet : bool
1046
- ``--quiet``
1047
- bare : bool
1048
- ``--bare``
1049
- object_format :
1050
- Hash algorithm used for objects. SHA-256 is still experimental as of git
1051
- 2.36.0.
1045
+ template : str, optional
1046
+ Directory from which templates will be used. The template directory
1047
+ contains files and directories that will be copied to the $GIT_DIR
1048
+ after it is created.
1049
+ separate_git_dir : :attr:`libvcs._internal.types.StrOrBytesPath`, optional
1050
+ Instead of placing the git repository in <directory>/.git/, place it in
1051
+ the specified path.
1052
+ object_format : "sha1" | "sha256", optional
1053
+ Specify the hash algorithm to use. The default is sha1. Note that
1054
+ sha256 is still experimental in git.
1055
+ branch : str, optional
1056
+ Use the specified name for the initial branch. If not specified, fall
1057
+ back to the default name (currently "master").
1058
+ initial_branch : str, optional
1059
+ Alias for branch parameter. Specify the name for the initial branch.
1060
+ shared : bool | str, optional
1061
+ Specify that the git repository is to be shared amongst several users.
1062
+ Can be 'false', 'true', 'umask', 'group', 'all', 'world',
1063
+ 'everybody', or an octal number.
1064
+ quiet : bool, optional
1065
+ Only print error and warning messages; all other output will be
1066
+ suppressed.
1067
+ bare : bool, optional
1068
+ Create a bare repository. If GIT_DIR environment is not set, it is set
1069
+ to the current working directory.
1052
1070
1053
1071
Examples
1054
1072
--------
1055
- >>> new_repo = tmp_path / 'example'
1056
- >>> new_repo.mkdir()
1057
- >>> git = Git(path=new_repo)
1073
+ >>> git = Git(path=tmp_path)
1058
1074
>>> git.init()
1059
1075
'Initialized empty Git repository in ...'
1060
- >>> pathlib.Path(new_repo / 'test').write_text('foo', 'utf-8')
1061
- 3
1062
- >>> git.run(['add', '.'])
1063
- ''
1064
1076
1065
- Bare :
1077
+ Create with a specific initial branch name :
1066
1078
1067
- >>> new_repo = tmp_path / 'example1 '
1079
+ >>> new_repo = tmp_path / 'branch_example '
1068
1080
>>> new_repo.mkdir()
1069
1081
>>> git = Git(path=new_repo)
1082
+ >>> git.init(branch='main')
1083
+ 'Initialized empty Git repository in ...'
1084
+
1085
+ Create a bare repository:
1086
+
1087
+ >>> bare_repo = tmp_path / 'bare_example'
1088
+ >>> bare_repo.mkdir()
1089
+ >>> git = Git(path=bare_repo)
1070
1090
>>> git.init(bare=True)
1071
1091
'Initialized empty Git repository in ...'
1072
- >>> pathlib.Path(new_repo / 'HEAD').exists()
1073
- True
1074
1092
1075
- Existing repo :
1093
+ Create with a separate git directory :
1076
1094
1077
- >>> git = Git(path=new_repo)
1078
- >>> git = Git(path=example_git_repo.path)
1079
- >>> git_remote_repo = create_git_remote_repo()
1080
- >>> git.init()
1081
- 'Reinitialized existing Git repository in ...'
1095
+ >>> repo_path = tmp_path / 'repo'
1096
+ >>> git_dir = tmp_path / 'git_dir'
1097
+ >>> repo_path.mkdir()
1098
+ >>> git_dir.mkdir()
1099
+ >>> git = Git(path=repo_path)
1100
+ >>> git.init(separate_git_dir=str(git_dir.absolute()))
1101
+ 'Initialized empty Git repository in ...'
1102
+
1103
+ Create with shared permissions:
1082
1104
1105
+ >>> shared_repo = tmp_path / 'shared_example'
1106
+ >>> shared_repo.mkdir()
1107
+ >>> git = Git(path=shared_repo)
1108
+ >>> git.init(shared='group')
1109
+ 'Initialized empty shared Git repository in ...'
1110
+
1111
+ Create with a template directory:
1112
+
1113
+ >>> template_repo = tmp_path / 'template_example'
1114
+ >>> template_repo.mkdir()
1115
+ >>> git = Git(path=template_repo)
1116
+ >>> git.init(template=str(tmp_path))
1117
+ 'Initialized empty Git repository in ...'
1083
1118
"""
1084
- required_flags : list [str ] = [str (self .path )]
1085
1119
local_flags : list [str ] = []
1120
+ required_flags : list [str ] = [str (self .path )]
1086
1121
1087
1122
if template is not None :
1088
1123
local_flags .append (f"--template={ template } " )
1089
1124
if separate_git_dir is not None :
1090
- local_flags .append (f"--separate-git-dir={ separate_git_dir !r} " )
1125
+ if isinstance (separate_git_dir , pathlib .Path ):
1126
+ separate_git_dir = str (separate_git_dir .absolute ())
1127
+ local_flags .append (f"--separate-git-dir={ separate_git_dir !s} " )
1091
1128
if object_format is not None :
1092
1129
local_flags .append (f"--object-format={ object_format } " )
1093
1130
if branch is not None :
1094
- local_flags .extend (["--branch" , branch ])
1095
- if initial_branch is not None :
1131
+ local_flags .extend (["--initial- branch" , branch ])
1132
+ elif initial_branch is not None :
1096
1133
local_flags .extend (["--initial-branch" , initial_branch ])
1097
- if shared is True :
1098
- local_flags .append ("--shared" )
1134
+ if shared is not None :
1135
+ if isinstance (shared , bool ):
1136
+ local_flags .append ("--shared" )
1137
+ else :
1138
+ local_flags .append (f"--shared={ shared } " )
1099
1139
if quiet is True :
1100
1140
local_flags .append ("--quiet" )
1101
1141
if bare is True :
0 commit comments