1+ import re
12import sys
23from enum import Enum
34import manim as m
1011
1112
1213class Stash (GitSimBaseCommand ):
13- def __init__ (self , files : List [str ], command : StashSubCommand ):
14+ def __init__ (self , files : List [str ], command : StashSubCommand , stash_index : int ):
1415 super ().__init__ ()
1516 self .files = files
1617 self .no_files = True if not self .files else False
1718 self .command = command
1819 settings .hide_merged_branches = True
1920 self .n = self .n_default
2021
22+ self .stash_index = self .parse_stash_format (stash_index )
23+ if self .stash_index is None :
24+ print (
25+ "git-sim error: specify stash index as either integer or stash@{i}"
26+ )
27+ sys .exit ()
28+
2129 try :
2230 self .selected_branches .append (self .repo .active_branch .name )
2331 except TypeError :
@@ -44,7 +52,7 @@ def __init__(self, files: List[str], command: StashSubCommand):
4452 and not settings .quiet
4553 ):
4654 print (
47- "Files are not required in apply/pop subcommand. Ignoring the file list..... "
55+ "Files are not required in apply/pop subcommand. Ignoring the file list..."
4856 )
4957
5058 self .cmd += f"{ type (self ).__name__ .lower ()} { self .command .value if self .command else '' } { ' ' .join (self .files ) if not self .no_files else '' } "
@@ -147,17 +155,21 @@ def populate_zones(
147155 thirdColumnArrowMap = {},
148156 ):
149157 if self .command in [StashSubCommand .POP , StashSubCommand .APPLY ]:
150- for x in self .repo .index .diff (None ):
151- thirdColumnFileNames .add (x .a_path )
152- firstColumnFileNames .add (x .a_path )
153- thirdColumnArrowMap [x .a_path ] = m .Arrow (
158+ try :
159+ stashedFileNames = self .repo .git .stash ("show" , "--name-only" , self .stash_index )
160+ stashedFileNames = stashedFileNames .split ("\n " )
161+ except :
162+ print (f"git-sim error: No stash entry with index { self .stashIndex } exists in stash" )
163+ sys .exit ()
164+ for s in stashedFileNames :
165+ thirdColumnFileNames .add (s )
166+ firstColumnFileNames .add (s )
167+ thirdColumnArrowMap [s ] = m .Arrow (
154168 stroke_width = 3 , color = self .fontColor
155169 )
156-
157- for y in self .repo .index .diff ("HEAD" ):
158- firstColumnFileNames .add (y .a_path )
159- thirdColumnFileNames .add (y .a_path )
160- thirdColumnArrowMap [y .a_path ] = m .Arrow (
170+ firstColumnFileNames .add (s )
171+ thirdColumnFileNames .add (s )
172+ thirdColumnArrowMap [s ] = m .Arrow (
161173 stroke_width = 3 , color = self .fontColor
162174 )
163175
@@ -179,3 +191,14 @@ def populate_zones(
179191 secondColumnArrowMap [y .a_path ] = m .Arrow (
180192 stroke_width = 3 , color = self .fontColor
181193 )
194+
195+ def parse_stash_format (self , s ):
196+ # Regular expression to match either a plain integer or stash@{integer}
197+ match = re .match (r"^(?:stash@\{(\d+)\}|\b(\d+)\b)$" , s )
198+ if match :
199+ # match.group(1) is the integer in the stash@{integer} format
200+ # match.group(2) is the integer if it's just a plain number
201+ # One of these groups will be None, the other will have our number as a string
202+ number_str = match .group (1 ) or match .group (2 )
203+ return int (number_str )
204+ return None
0 commit comments