Commit 3286550 1 parent e9b61d2 commit 3286550 Copy full SHA for 3286550
File tree 1 file changed +21
-7
lines changed
crates/rover-client/src/shared
1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -103,13 +103,7 @@ impl GitContext {
103
103
// will return None
104
104
fn sanitize_remote_url ( remote_url : & str ) -> Option < String > {
105
105
// try to parse url into git info
106
-
107
- // GitUrl::parse can panic, so we attempt to catch it and
108
- // just return None if the parsing fails.
109
-
110
- let parsed_remote_url = panic:: catch_unwind ( || GitUrl :: parse ( remote_url) . ok ( ) )
111
- . ok ( )
112
- . flatten ( ) ;
106
+ let parsed_remote_url = parse_git_remote ( remote_url) ;
113
107
114
108
if let Some ( mut parsed_remote_url) = parsed_remote_url {
115
109
// return None for any remote that is not a supported host
@@ -142,6 +136,26 @@ impl GitContext {
142
136
}
143
137
}
144
138
139
+ // GitUrl::parse can panic, so we attempt to catch it and
140
+ // just return None if the parsing fails.
141
+ fn parse_git_remote ( remote_url : & str ) -> Option < GitUrl > {
142
+ // we make sure to store the original panic handler
143
+ let original_panic_handler = panic:: take_hook ( ) ;
144
+
145
+ // set a new hook to suppress the panic message
146
+ panic:: set_hook ( Box :: new ( |_| { } ) ) ;
147
+
148
+ // parse the git remote
149
+ let parsed_remote_url = panic:: catch_unwind ( || GitUrl :: parse ( remote_url) . ok ( ) )
150
+ . ok ( )
151
+ . flatten ( ) ;
152
+
153
+ // and restore the original panic handler
154
+ panic:: set_hook ( original_panic_handler) ;
155
+
156
+ parsed_remote_url
157
+ }
158
+
145
159
#[ cfg( test) ]
146
160
mod tests {
147
161
use super :: * ;
You can’t perform that action at this time.
0 commit comments