@@ -85,12 +85,26 @@ def parse_url(url: str) -> dict:
8585 parsed ["local_path" ] = f"{ TMP_BASE_PATH } /{ parsed ['id' ]} /{ parsed ['slug' ]} "
8686
8787 if len (path_parts ) > 3 :
88- parsed ["type" ] = path_parts [2 ]
89- parsed ["branch" ] = path_parts [3 ]
90- if len (parsed ['branch' ]) == 40 and all (c in '0123456789abcdefABCDEF' for c in parsed ['branch' ]):
91- parsed ["commit" ] = parsed ['branch' ]
92-
93- parsed ["subpath" ] = "/" + "/" .join (path_parts [4 :])
88+ parsed ["type" ] = path_parts [2 ] # Usually 'tree' or 'blob'
89+
90+ # Find the commit hash or reconstruct the branch name
91+ remaining_parts = path_parts [3 :]
92+ if remaining_parts [0 ] and len (remaining_parts [0 ]) == 40 and all (c in '0123456789abcdefABCDEF' for c in remaining_parts [0 ]):
93+ parsed ["commit" ] = remaining_parts [0 ]
94+ parsed ["subpath" ] = "/" + "/" .join (remaining_parts [1 :]) if len (remaining_parts ) > 1 else "/"
95+ else :
96+ # Handle branch names with slashes
97+ for i , part in enumerate (remaining_parts ):
98+ if part in ('tree' , 'blob' ):
99+ # Found another type indicator, everything before this was the branch name
100+ parsed ["branch" ] = "/" .join (remaining_parts [:i ])
101+ parsed ["subpath" ] = "/" + "/" .join (remaining_parts [i + 2 :]) if len (remaining_parts ) > i + 2 else "/"
102+ break
103+ else :
104+ # No additional type indicator found, assume everything is part of the branch name
105+ parsed ["branch" ] = "/" .join (remaining_parts )
106+ parsed ["subpath" ] = "/"
107+
94108 return parsed
95109
96110def normalize_pattern (pattern : str ) -> str :
0 commit comments