@@ -2056,53 +2056,48 @@ int git_repository_init_ext(
20562056 const char * given_repo ,
20572057 git_repository_init_options * opts )
20582058{
2059- int error ;
2060- git_buf repo_path = GIT_BUF_INIT , wd_path = GIT_BUF_INIT ,
2061- common_path = GIT_BUF_INIT ;
2059+ git_buf repo_path = GIT_BUF_INIT , wd_path = GIT_BUF_INIT , common_path = GIT_BUF_INIT ;
20622060 const char * wd ;
2061+ int error ;
20632062
20642063 assert (out && given_repo && opts );
20652064
20662065 GIT_ERROR_CHECK_VERSION (opts , GIT_REPOSITORY_INIT_OPTIONS_VERSION , "git_repository_init_options" );
20672066
2068- error = repo_init_directories (& repo_path , & wd_path , given_repo , opts );
2069- if (error < 0 )
2070- goto cleanup ;
2067+ if ((error = repo_init_directories (& repo_path , & wd_path , given_repo , opts )) < 0 )
2068+ goto out ;
20712069
20722070 wd = (opts -> flags & GIT_REPOSITORY_INIT_BARE ) ? NULL : git_buf_cstr (& wd_path );
2073- if (valid_repository_path (& repo_path , & common_path )) {
20742071
2072+ if (valid_repository_path (& repo_path , & common_path )) {
20752073 if ((opts -> flags & GIT_REPOSITORY_INIT_NO_REINIT ) != 0 ) {
20762074 git_error_set (GIT_ERROR_REPOSITORY ,
20772075 "attempt to reinitialize '%s'" , given_repo );
20782076 error = GIT_EEXISTS ;
2079- goto cleanup ;
2077+ goto out ;
20802078 }
20812079
20822080 opts -> flags |= GIT_REPOSITORY_INIT__IS_REINIT ;
20832081
2084- error = repo_init_config (
2085- repo_path . ptr , wd , opts -> flags , opts -> mode ) ;
2082+ if (( error = repo_init_config (repo_path . ptr , wd , opts -> flags , opts -> mode )) < 0 )
2083+ goto out ;
20862084
20872085 /* TODO: reinitialize the templates */
2086+ } else {
2087+ if ((error = repo_init_structure (repo_path .ptr , wd , opts )) < 0 ||
2088+ (error = repo_init_config (repo_path .ptr , wd , opts -> flags , opts -> mode )) < 0 ||
2089+ (error = git_repository_create_head (repo_path .ptr , opts -> initial_head )) < 0 )
2090+ goto out ;
20882091 }
2089- else {
2090- if (!(error = repo_init_structure (
2091- repo_path .ptr , wd , opts )) &&
2092- !(error = repo_init_config (
2093- repo_path .ptr , wd , opts -> flags , opts -> mode )))
2094- error = git_repository_create_head (
2095- repo_path .ptr , opts -> initial_head );
2096- }
2097- if (error < 0 )
2098- goto cleanup ;
20992092
2100- error = git_repository_open (out , repo_path .ptr );
2093+ if ((error = git_repository_open (out , repo_path .ptr )) < 0 )
2094+ goto out ;
21012095
2102- if (!error && opts -> origin_url )
2103- error = repo_init_create_origin (* out , opts -> origin_url );
2096+ if (opts -> origin_url &&
2097+ (error = repo_init_create_origin (* out , opts -> origin_url )) < 0 )
2098+ goto out ;
21042099
2105- cleanup :
2100+ out :
21062101 git_buf_dispose (& common_path );
21072102 git_buf_dispose (& repo_path );
21082103 git_buf_dispose (& wd_path );
0 commit comments