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" ),
@@ -114,9 +114,36 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
114114 )
115115 # NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
116116 # type error
117- def get ( # type: ignore
118- self , file_path : str , ref : str , ** kwargs : Any
119- ) -> ProjectFile :
117+ def head (self , file_path : str , ref : str , ** kwargs : Any ) -> ProjectFile :
118+ """Retrieve just metadata for a single file.
119+
120+ Args:
121+ file_path: Path of the file to retrieve
122+ ref: Name of the branch, tag or commit
123+ **kwargs: Extra options to send to the server (e.g. sudo)
124+
125+ Raises:
126+ GitlabAuthenticationError: If authentication is not correct
127+ GitlabGetError: If the file could not be retrieved
128+
129+ Returns:
130+ The generated RESTObject
131+ """
132+ if TYPE_CHECKING :
133+ assert file_path is not None
134+ file_path = utils .EncodedId (file_path )
135+ path = f"{ self .path } /{ file_path } "
136+ server_data_headers = self .gitlab .http_head (path , ref = ref , ** kwargs )
137+ server_data = {
138+ key .replace ("X-Gitlab-" , "" ).replace ("-" , "_" ).lower (): value
139+ for key , value in server_data_headers .items ()
140+ if key .startswith ("X-Gitlab-" ) and key != "X-Gitlab-Meta"
141+ }
142+ if TYPE_CHECKING :
143+ assert isinstance (server_data , dict )
144+ return self ._obj_cls (self , server_data )
145+
146+ def get (self , file_path : str , ref : str , ** kwargs : Any ) -> ProjectFile :
120147 """Retrieve a single file.
121148
122149 Args:
@@ -131,7 +158,14 @@ def get( # type: ignore
131158 Returns:
132159 The generated RESTObject
133160 """
134- return cast (ProjectFile , GetMixin .get (self , file_path , ref = ref , ** kwargs ))
161+ if TYPE_CHECKING :
162+ assert file_path is not None
163+ file_path = utils .EncodedId (file_path )
164+ path = f"{ self .path } /{ file_path } "
165+ server_data = self .gitlab .http_get (path , ref = ref , ** kwargs )
166+ if TYPE_CHECKING :
167+ assert isinstance (server_data , dict )
168+ return self ._obj_cls (self , server_data )
135169
136170 @cli .register_custom_action (
137171 cls_names = "ProjectFileManager" ,
0 commit comments