@@ -1035,7 +1035,10 @@ def init(
1035
1035
object_format : t .Literal ["sha1" , "sha256" ] | None = None ,
1036
1036
branch : str | None = None ,
1037
1037
initial_branch : str | None = None ,
1038
- shared : bool | str | None = None ,
1038
+ shared : bool
1039
+ | Literal [false , true , umask , group , all , world , everybody ]
1040
+ | str
1041
+ | None = None ,
1039
1042
quiet : bool | None = None ,
1040
1043
bare : bool | None = None ,
1041
1044
# libvcs special behavior
@@ -1049,28 +1052,58 @@ def init(
1049
1052
template : str, optional
1050
1053
Directory from which templates will be used. The template directory
1051
1054
contains files and directories that will be copied to the $GIT_DIR
1052
- after it is created.
1055
+ after it is created. The template directory will be one of the
1056
+ following (in order):
1057
+ - The argument given with the --template option
1058
+ - The contents of the $GIT_TEMPLATE_DIR environment variable
1059
+ - The init.templateDir configuration variable
1060
+ - The default template directory: /usr/share/git-core/templates
1053
1061
separate_git_dir : :attr:`libvcs._internal.types.StrOrBytesPath`, optional
1054
1062
Instead of placing the git repository in <directory>/.git/, place it in
1055
- the specified path.
1063
+ the specified path. The .git file at <directory>/.git will contain a
1064
+ gitfile that points to the separate git dir. This is useful when you
1065
+ want to store the git directory on a different disk or filesystem.
1056
1066
object_format : "sha1" | "sha256", optional
1057
1067
Specify the hash algorithm to use. The default is sha1. Note that
1058
- sha256 is still experimental in git.
1068
+ sha256 is still experimental in git and requires git version >= 2.29.0.
1069
+ Once the repository is created with a specific hash algorithm, it cannot
1070
+ be changed.
1059
1071
branch : str, optional
1060
1072
Use the specified name for the initial branch. If not specified, fall
1061
- back to the default name (currently "master").
1073
+ back to the default name (currently "master", but may change based on
1074
+ init.defaultBranch configuration).
1062
1075
initial_branch : str, optional
1063
1076
Alias for branch parameter. Specify the name for the initial branch.
1077
+ This is provided for compatibility with newer git versions.
1064
1078
shared : bool | str, optional
1065
1079
Specify that the git repository is to be shared amongst several users.
1066
- Can be 'false', 'true', 'umask', 'group', 'all', 'world',
1067
- 'everybody', or an octal number.
1080
+ Valid values are:
1081
+ - false: Turn off sharing (default)
1082
+ - true: Same as group
1083
+ - umask: Use permissions specified by umask
1084
+ - group: Make the repository group-writable
1085
+ - all, world, everybody: Same as world, make repo readable by all users
1086
+ - An octal number: Explicit mode specification (e.g., "0660")
1068
1087
quiet : bool, optional
1069
1088
Only print error and warning messages; all other output will be
1070
- suppressed.
1089
+ suppressed. Useful for scripting.
1071
1090
bare : bool, optional
1072
1091
Create a bare repository. If GIT_DIR environment is not set, it is set
1073
- to the current working directory.
1092
+ to the current working directory. Bare repositories have no working
1093
+ tree and are typically used as central repositories.
1094
+ check_returncode : bool, optional
1095
+ If True, check the return code of the git command and raise a
1096
+ CalledProcessError if it is non-zero.
1097
+
1098
+ Returns
1099
+ -------
1100
+ str
1101
+ The output of the git init command.
1102
+
1103
+ Raises
1104
+ ------
1105
+ CalledProcessError
1106
+ If the git command fails and check_returncode is True.
1074
1107
1075
1108
Examples
1076
1109
--------
@@ -1119,6 +1152,13 @@ def init(
1119
1152
>>> git = Git(path=template_repo)
1120
1153
>>> git.init(template=str(tmp_path))
1121
1154
'Initialized empty Git repository in ...'
1155
+
1156
+ Create with SHA-256 object format (requires git >= 2.29.0):
1157
+
1158
+ >>> sha256_repo = tmp_path / 'sha256_example'
1159
+ >>> sha256_repo.mkdir()
1160
+ >>> git = Git(path=sha256_repo)
1161
+ >>> git.init(object_format='sha256') # doctest: +SKIP
1122
1162
"""
1123
1163
local_flags : list [str ] = []
1124
1164
required_flags : list [str ] = [str (self .path )]
0 commit comments