@@ -53,13 +53,28 @@ func (i *initCmd) Run(ctx context.Context, args []string) error {
5353 bundleProvider := utils .GetDependency [bundles.BundleProvider ](ctx , i .container )
5454 gitHelper := utils .GetDependency [git.GitHelper ](ctx , i .container )
5555
56+ // First, check whether route already exists (enabled or not). If it does,
57+ // exit with an error.
58+ allRepos , err := repoProvider .ReadRepositoryStorage (ctx )
59+ if err != nil {
60+ return i .logger .Errorf (ctx , "could not load existing routes: %w" , err )
61+ } else if _ , ok := allRepos [* route ]; ok {
62+ return i .logger .Errorf (ctx , "route '%s' already exists; if you want to " +
63+ "overwrite the route, delete it with 'git-bundle-server delete' " +
64+ "then re-run this command" , * route )
65+ }
66+
67+ // Create the new route
5668 repo , err := repoProvider .CreateRepository (ctx , * route )
5769 if err != nil {
5870 return i .logger .Error (ctx , err )
5971 }
6072
6173 fmt .Printf ("Cloning repository from %s\n " , * url )
62- gitHelper .CloneBareRepo (ctx , * url , repo .RepoDir )
74+ err = gitHelper .CloneBareRepo (ctx , * url , repo .RepoDir )
75+ if err != nil {
76+ return i .logger .Errorf (ctx , "failed to clone repository: %w" , err )
77+ }
6378
6479 bundle := bundleProvider .CreateInitialBundle (ctx , repo )
6580 fmt .Printf ("Constructing base bundle file at %s\n " , bundle .Filename )
0 commit comments