@@ -120,7 +120,10 @@ impl Install {
120
120
let template_manager = TemplateManager :: try_default ( )
121
121
. context ( "Failed to construct template directory path" ) ?;
122
122
let source = match ( & self . git , & self . dir ) {
123
- ( Some ( git) , None ) => TemplateSource :: try_from_git ( git, & self . branch , SPIN_VERSION ) ?,
123
+ ( Some ( git) , None ) => {
124
+ let git_url = infer_github ( git) ;
125
+ TemplateSource :: try_from_git ( git_url, & self . branch , SPIN_VERSION ) ?
126
+ }
124
127
( None , Some ( dir) ) => {
125
128
let abs_dir = dir. absolutize ( ) . map ( |d| d. to_path_buf ( ) ) ;
126
129
TemplateSource :: File ( abs_dir. unwrap_or_else ( |_| dir. clone ( ) ) )
@@ -180,6 +183,19 @@ impl Install {
180
183
}
181
184
}
182
185
186
+ fn infer_github ( raw : & str ) -> String {
187
+ match url:: Url :: parse ( raw) {
188
+ Err ( url:: ParseError :: RelativeUrlWithoutBase ) => {
189
+ if raw. starts_with ( '/' ) {
190
+ format ! ( "https://github.com{raw}" )
191
+ } else {
192
+ format ! ( "https://github.com/{raw}" )
193
+ }
194
+ }
195
+ _ => raw. to_string ( ) , // pass it through even if error, so Git can have a try
196
+ }
197
+ }
198
+
183
199
impl Upgrade {
184
200
pub async fn run ( & self ) -> Result < ( ) > {
185
201
if self . git . is_some ( ) {
@@ -612,3 +628,24 @@ async fn install_default_templates() -> anyhow::Result<()> {
612
628
. context ( "Failed to install the default templates" ) ?;
613
629
Ok ( ( ) )
614
630
}
631
+
632
+ #[ cfg( test) ]
633
+ mod tests {
634
+ use super :: * ;
635
+
636
+ #[ test]
637
+ fn infers_github_url_if_needed ( ) {
638
+ assert_eq ! (
639
+ "https://github.com/fermyon/spin" ,
640
+ infer_github( "fermyon/spin" )
641
+ ) ;
642
+ assert_eq ! (
643
+ "https://github.com/fermyon/spin" ,
644
+ infer_github( "/fermyon/spin" )
645
+ ) ;
646
+ assert_eq ! (
647
+ "https://github.com/fermyon/spin" ,
648
+ infer_github( "https://github.com/fermyon/spin" )
649
+ ) ;
650
+ }
651
+ }
0 commit comments