File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -317,12 +317,17 @@ def restore(
317317 files : List [str ] = typer .Argument (
318318 default = None ,
319319 help = "The names of one or more files to restore" ,
320- )
320+ ),
321+ staged : bool = typer .Option (
322+ False ,
323+ "--staged" ,
324+ help = "Restore staged file to working directory" ,
325+ ),
321326):
322327 from git_sim .restore import Restore
323328
324329 settings .hide_first_tag = True
325- scene = Restore (files = files )
330+ scene = Restore (files = files , staged = staged )
326331 handle_animations (scene = scene )
327332
328333
Original file line number Diff line number Diff line change 88
99
1010class Restore (GitSimBaseCommand ):
11- def __init__ (self , files : List [str ]):
11+ def __init__ (self , files : List [str ], staged : bool ):
1212 super ().__init__ ()
1313 self .files = files
14+ self .staged = staged
1415 settings .hide_merged_branches = True
1516 self .n = self .n_default
1617
@@ -19,14 +20,18 @@ def __init__(self, files: List[str]):
1920 except TypeError :
2021 pass
2122
22- for file in self .files :
23- if file not in [x .a_path for x in self .repo .index .diff (None )] + [
24- y .a_path for y in self .repo .index .diff ("HEAD" )
25- ]:
26- print (f"git-sim error: No modified or staged file with name: '{ file } '" )
27- sys .exit ()
23+ if not self .staged :
24+ for file in self .files :
25+ if file not in [x .a_path for x in self .repo .index .diff (None )]:
26+ print (f"git-sim error: No modified file with name: '{ file } '" )
27+ sys .exit ()
28+ else :
29+ for file in self .files :
30+ if file not in [y .a_path for y in self .repo .index .diff ("HEAD" )]:
31+ print (f"git-sim error: No modified or staged file with name: '{ file } '" )
32+ sys .exit ()
2833
29- self .cmd += f"{ type (self ).__name__ .lower ()} { ' ' .join (self .files )} "
34+ self .cmd += f"{ type (self ).__name__ .lower ()} { ' --staged' if self . staged else '' } { ' ' .join (self .files )} "
3035
3136 def construct (self ):
3237 if not settings .stdout and not settings .output_only_path and not settings .quiet :
You can’t perform that action at this time.
0 commit comments