@@ -409,6 +409,7 @@ static int cmd_clone(int argc, const char **argv)
409409{
410410 const char * branch = NULL ;
411411 int full_clone = 0 , single_branch = 0 , show_progress = isatty (2 );
412+ int src = 1 ;
412413 struct option clone_options [] = {
413414 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
414415 N_ ("branch to checkout after clone" )),
@@ -417,10 +418,13 @@ static int cmd_clone(int argc, const char **argv)
417418 OPT_BOOL (0 , "single-branch" , & single_branch ,
418419 N_ ("only download metadata for the branch that will "
419420 "be checked out" )),
421+ OPT_BOOL (0 , "src" , & src ,
422+ N_ ("create repository within 'src' directory" )),
420423 OPT_END (),
421424 };
422425 const char * const clone_usage [] = {
423- N_ ("scalar clone [<options>] [--] <repo> [<dir>]" ),
426+ N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
427+ "\t[--[no-]src] <url> [<enlistment>]" ),
424428 NULL
425429 };
426430 const char * url ;
@@ -456,7 +460,10 @@ static int cmd_clone(int argc, const char **argv)
456460 if (is_directory (enlistment ))
457461 die (_ ("directory '%s' exists already" ), enlistment );
458462
459- dir = xstrfmt ("%s/src" , enlistment );
463+ if (src )
464+ dir = xstrfmt ("%s/src" , enlistment );
465+ else
466+ dir = xstrdup (enlistment );
460467
461468 strbuf_reset (& buf );
462469 if (branch )
@@ -657,6 +664,7 @@ static int cmd_reconfigure(int argc, const char **argv)
657664 git_config (get_scalar_repos , & scalar_repos );
658665
659666 for (i = 0 ; i < scalar_repos .nr ; i ++ ) {
667+ int succeeded = 0 ;
660668 const char * dir = scalar_repos .items [i ].string ;
661669
662670 strbuf_reset (& commondir );
@@ -667,30 +675,56 @@ static int cmd_reconfigure(int argc, const char **argv)
667675
668676 if (errno != ENOENT ) {
669677 warning_errno (_ ("could not switch to '%s'" ), dir );
670- res = -1 ;
671- continue ;
678+ goto loop_end ;
672679 }
673680
674681 strbuf_addstr (& buf , dir );
675682 if (remove_deleted_enlistment (& buf ))
676- res = error (_ ("could not remove stale "
677- "scalar.repo '%s'" ), dir );
678- else
679- warning (_ ("removing stale scalar.repo '%s'" ),
683+ error (_ ("could not remove stale "
684+ "scalar.repo '%s'" ), dir );
685+ else {
686+ warning (_ ("removed stale scalar.repo '%s'" ),
680687 dir );
688+ succeeded = 1 ;
689+ }
681690 strbuf_release (& buf );
682- } else if (discover_git_directory (& commondir , & gitdir ) < 0 ) {
683- warning_errno (_ ("git repository gone in '%s'" ), dir );
684- res = -1 ;
685- } else {
686- git_config_clear ();
691+ goto loop_end ;
692+ }
693+
694+ switch (discover_git_directory_reason (& commondir , & gitdir )) {
695+ case GIT_DIR_INVALID_OWNERSHIP :
696+ warning (_ ("repository at '%s' has different owner" ), dir );
697+ goto loop_end ;
698+
699+ case GIT_DIR_INVALID_GITFILE :
700+ case GIT_DIR_INVALID_FORMAT :
701+ warning (_ ("repository at '%s' has a format issue" ), dir );
702+ goto loop_end ;
703+
704+ case GIT_DIR_DISCOVERED :
705+ succeeded = 1 ;
706+ break ;
707+
708+ default :
709+ warning (_ ("repository not found in '%s'" ), dir );
710+ break ;
711+ }
687712
688- the_repository = & r ;
689- r .commondir = commondir .buf ;
690- r .gitdir = gitdir .buf ;
713+ git_config_clear ();
691714
692- if (set_recommended_config (1 ) < 0 )
693- res = -1 ;
715+ the_repository = & r ;
716+ r .commondir = commondir .buf ;
717+ r .gitdir = gitdir .buf ;
718+
719+ if (set_recommended_config (1 ) >= 0 )
720+ succeeded = 1 ;
721+
722+ loop_end :
723+ if (!succeeded ) {
724+ res = -1 ;
725+ warning (_ ("to unregister this repository from Scalar, run\n"
726+ "\tgit config --global --unset --fixed-value scalar.repo \"%s\"" ),
727+ dir );
694728 }
695729 }
696730
0 commit comments