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