22from typing import (
33 Any ,
44 Callable ,
5- cast ,
65 Dict ,
76 Iterator ,
87 List ,
98 Optional ,
9+ Tuple ,
1010 TYPE_CHECKING ,
1111 Union ,
1212)
2020from gitlab .mixins import (
2121 CreateMixin ,
2222 DeleteMixin ,
23- GetMixin ,
2423 ObjectDeleteMixin ,
2524 SaveMixin ,
2625 UpdateMixin ,
@@ -96,10 +95,11 @@ def delete( # type: ignore
9695 self .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 (
104104 required = ("file_path" , "branch" , "content" , "commit_message" ),
105105 optional = ("encoding" , "author_email" , "author_name" ),
@@ -112,11 +112,36 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
112112 @cli .register_custom_action (
113113 cls_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 head (self , file_path : str , ref : str , ** kwargs : Any ) -> ProjectFile :
116+ """Retrieve just metadata for a single file.
117+
118+ Args:
119+ file_path: Path of the file to retrieve
120+ ref: Name of the branch, tag or commit
121+ **kwargs: Extra options to send to the server (e.g. sudo)
122+
123+ Raises:
124+ GitlabAuthenticationError: If authentication is not correct
125+ GitlabGetError: If the file could not be retrieved
126+
127+ Returns:
128+ The generated RESTObject
129+ """
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_headers = self .gitlab .http_head (path , ref = ref , ** kwargs )
135+ server_data = {
136+ key .replace ("X-Gitlab-" , "" ).replace ("-" , "_" ).lower (): value
137+ for key , value in server_data_headers .items ()
138+ if key .startswith ("X-Gitlab-" ) and key != "X-Gitlab-Meta"
139+ }
140+ if TYPE_CHECKING :
141+ assert isinstance (server_data , dict )
142+ return self ._obj_cls (self , server_data )
143+
144+ def get (self , file_path : str , ref : str , ** kwargs : Any ) -> ProjectFile :
120145 """Retrieve a single file.
121146
122147 Args:
@@ -131,7 +156,14 @@ def get( # type: ignore
131156 Returns:
132157 The generated RESTObject
133158 """
134- return cast (ProjectFile , GetMixin .get (self , file_path , ref = ref , ** kwargs ))
159+ if TYPE_CHECKING :
160+ assert file_path is not None
161+ file_path = utils .EncodedId (file_path )
162+ path = f"{ self .path } /{ file_path } "
163+ server_data = self .gitlab .http_get (path , ref = ref , ** kwargs )
164+ if TYPE_CHECKING :
165+ assert isinstance (server_data , dict )
166+ return self ._obj_cls (self , server_data )
135167
136168 @cli .register_custom_action (
137169 cls_names = "ProjectFileManager" ,
0 commit comments