22from typing import (
33Any ,
44Callable ,
5- cast ,
65Dict ,
76Iterator ,
87List ,
98Optional ,
9+ Tuple ,
1010TYPE_CHECKING ,
1111Union ,
1212)
2020from gitlab .mixins import (
2121CreateMixin ,
2222DeleteMixin ,
23- GetMixin ,
2423ObjectDeleteMixin ,
2524SaveMixin ,
2625UpdateMixin ,
@@ -96,10 +95,11 @@ def delete( # type: ignore
9695self .manager .delete (file_path ,branch ,commit_message ,** kwargs )
9796
9897
99- class ProjectFileManager (GetMixin , CreateMixin ,UpdateMixin ,DeleteMixin ,RESTManager ):
98+ class ProjectFileManager (CreateMixin ,UpdateMixin ,DeleteMixin ,RESTManager ):
10099_path = "/projects/{project_id}/repository/files"
101100_obj_cls = ProjectFile
102101_from_parent_attrs = {"project_id" :"id" }
102+ _optional_get_attrs :Tuple [str , ...]= ()
103103_create_attrs = RequiredOptional (
104104required = ("file_path" ,"branch" ,"content" ,"commit_message" ),
105105optional = ("encoding" ,"author_email" ,"author_name" ),
@@ -112,11 +112,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
112112@cli .register_custom_action (
113113cls_names = "ProjectFileManager" ,required = ("file_path" ,"ref" )
114114 )
115- # NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
116- # type error
117- def get (# type: ignore
118- self ,file_path :str ,ref :str ,** kwargs :Any
119- )-> ProjectFile :
115+ def get (self ,file_path :str ,ref :str ,** kwargs :Any )-> ProjectFile :
120116"""Retrieve a single file.
121117
122118 Args:
@@ -131,7 +127,37 @@ def get( # type: ignore
131127 Returns:
132128 The generated RESTObject
133129 """
134- return cast (ProjectFile ,GetMixin .get (self ,file_path ,ref = ref ,** kwargs ))
130+ if TYPE_CHECKING :
131+ assert file_path is not None
132+ file_path = utils .EncodedId (file_path )
133+ path = f"{ self .path } /{ file_path } "
134+ server_data = self .gitlab .http_get (path ,ref = ref ,** kwargs )
135+ if TYPE_CHECKING :
136+ assert isinstance (server_data ,dict )
137+ return self ._obj_cls (self ,server_data )
138+
139+ def head (
140+ self ,file_path :str ,ref :str ,** kwargs :Any
141+ )-> "requests.structures.CaseInsensitiveDict[Any]" :
142+ """Retrieve just metadata for a single file.
143+
144+ Args:
145+ file_path: Path of the file to retrieve
146+ ref: Name of the branch, tag or commit
147+ **kwargs: Extra options to send to the server (e.g. sudo)
148+
149+ Raises:
150+ GitlabAuthenticationError: If authentication is not correct
151+ GitlabGetError: If the file could not be retrieved
152+
153+ Returns:
154+ The response headers as a dictionary
155+ """
156+ if TYPE_CHECKING :
157+ assert file_path is not None
158+ file_path = utils .EncodedId (file_path )
159+ path = f"{ self .path } /{ file_path } "
160+ return self .gitlab .http_head (path ,ref = ref ,** kwargs )
135161
136162@cli .register_custom_action (
137163cls_names = "ProjectFileManager" ,