@@ -53,13 +53,28 @@ func (i *initCmd) Run(ctx context.Context, args []string) error {
53
53
bundleProvider := utils .GetDependency [bundles.BundleProvider ](ctx , i .container )
54
54
gitHelper := utils .GetDependency [git.GitHelper ](ctx , i .container )
55
55
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
56
68
repo , err := repoProvider .CreateRepository (ctx , * route )
57
69
if err != nil {
58
70
return i .logger .Error (ctx , err )
59
71
}
60
72
61
73
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
+ }
63
78
64
79
bundle := bundleProvider .CreateInitialBundle (ctx , repo )
65
80
fmt .Printf ("Constructing base bundle file at %s\n " , bundle .Filename )
0 commit comments