55 "encoding/json"
66 "io/ioutil"
77 "os/exec"
8+ "reflect"
89 "regexp"
910 "strings"
1011 "testing"
@@ -337,6 +338,65 @@ func TestRepoFork_in_parent_survey_no(t *testing.T) {
337338 }
338339}
339340
341+ func TestParseExtraArgs (t * testing.T ) {
342+ type Wanted struct {
343+ args []string
344+ dir string
345+ }
346+ tests := []struct {
347+ name string
348+ args []string
349+ want Wanted
350+ }{
351+ {
352+ name : "args and target" ,
353+ args : []string {"target_directory" , "-o" , "upstream" , "--depth" , "1" },
354+ want : Wanted {
355+ args : []string {"-o" , "upstream" , "--depth" , "1" },
356+ dir : "target_directory" ,
357+ },
358+ },
359+ {
360+ name : "only args" ,
361+ args : []string {"-o" , "upstream" , "--depth" , "1" },
362+ want : Wanted {
363+ args : []string {"-o" , "upstream" , "--depth" , "1" },
364+ dir : "" ,
365+ },
366+ },
367+ {
368+ name : "only target" ,
369+ args : []string {"target_directory" },
370+ want : Wanted {
371+ args : []string {},
372+ dir : "target_directory" ,
373+ },
374+ },
375+ {
376+ name : "no args" ,
377+ args : []string {},
378+ want : Wanted {
379+ args : []string {},
380+ dir : "" ,
381+ },
382+ },
383+ }
384+ for _ , tt := range tests {
385+ t .Run (tt .name , func (t * testing.T ) {
386+ args , dir := parseExtraArgs (tt .args )
387+ got := Wanted {
388+ args : args ,
389+ dir : dir ,
390+ }
391+
392+ if ! reflect .DeepEqual (got , tt .want ) {
393+ t .Errorf ("got %#v want %#v" , got , tt .want )
394+ }
395+ })
396+ }
397+
398+ }
399+
340400func TestRepoClone (t * testing.T ) {
341401 tests := []struct {
342402 name string
@@ -348,11 +408,21 @@ func TestRepoClone(t *testing.T) {
348408 args : "repo clone OWNER/REPO" ,
349409 want : "git clone https://github.com/OWNER/REPO.git" ,
350410 },
411+ {
412+ name : "shorthand with directory" ,
413+ args : "repo clone OWNER/REPO target_directory" ,
414+ want : "git clone https://github.com/OWNER/REPO.git target_directory" ,
415+ },
351416 {
352417 name : "clone arguments" ,
353418 args : "repo clone OWNER/REPO -- -o upstream --depth 1" ,
354419 want : "git clone -o upstream --depth 1 https://github.com/OWNER/REPO.git" ,
355420 },
421+ {
422+ name : "clone arguments with directory" ,
423+ args : "repo clone OWNER/REPO target_directory -- -o upstream --depth 1" ,
424+ want : "git clone -o upstream --depth 1 https://github.com/OWNER/REPO.git target_directory" ,
425+ },
356426 {
357427 name : "HTTPS URL" ,
358428 args : "repo clone https://github.com/OWNER/REPO" ,
0 commit comments