@@ -329,6 +329,9 @@ static int checkout_target_fullpath(
329329 if (path && git_buf_puts (& data -> target_path , path ) < 0 )
330330 return -1 ;
331331
332+ if (git_path_validate_workdir_buf (data -> repo , & data -> target_path ) < 0 )
333+ return -1 ;
334+
332335 * out = & data -> target_path ;
333336
334337 return 0 ;
@@ -1278,14 +1281,14 @@ static int checkout_verify_paths(
12781281 unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS ;
12791282
12801283 if (action & CHECKOUT_ACTION__REMOVE ) {
1281- if (!git_path_isvalid (repo , delta -> old_file .path , delta -> old_file .mode , flags )) {
1284+ if (!git_path_validate (repo , delta -> old_file .path , delta -> old_file .mode , flags )) {
12821285 git_error_set (GIT_ERROR_CHECKOUT , "cannot remove invalid path '%s'" , delta -> old_file .path );
12831286 return -1 ;
12841287 }
12851288 }
12861289
12871290 if (action & ~CHECKOUT_ACTION__REMOVE ) {
1288- if (!git_path_isvalid (repo , delta -> new_file .path , delta -> new_file .mode , flags )) {
1291+ if (!git_path_validate (repo , delta -> new_file .path , delta -> new_file .mode , flags )) {
12891292 git_error_set (GIT_ERROR_CHECKOUT , "cannot checkout to invalid path '%s'" , delta -> new_file .path );
12901293 return -1 ;
12911294 }
@@ -2032,7 +2035,8 @@ static int checkout_merge_path(
20322035 const char * our_label_raw , * their_label_raw , * suffix ;
20332036 int error = 0 ;
20342037
2035- if ((error = git_buf_joinpath (out , git_repository_workdir (data -> repo ), result -> path )) < 0 )
2038+ if ((error = git_buf_joinpath (out , data -> opts .target_directory , result -> path )) < 0 ||
2039+ (error = git_path_validate_workdir_buf (data -> repo , out )) < 0 )
20362040 return error ;
20372041
20382042 /* Most conflicts simply use the filename in the index */
@@ -2331,6 +2335,22 @@ static void checkout_data_clear(checkout_data *data)
23312335 git_attr_session__free (& data -> attr_session );
23322336}
23332337
2338+ static int validate_target_directory (checkout_data * data )
2339+ {
2340+ int error ;
2341+
2342+ if ((error = git_path_validate_workdir (data -> repo , data -> opts .target_directory )) < 0 )
2343+ return error ;
2344+
2345+ if (git_path_isdir (data -> opts .target_directory ))
2346+ return 0 ;
2347+
2348+ error = checkout_mkdir (data , data -> opts .target_directory , NULL ,
2349+ GIT_DIR_MODE , GIT_MKDIR_VERIFY_DIR );
2350+
2351+ return error ;
2352+ }
2353+
23342354static int checkout_data_init (
23352355 checkout_data * data ,
23362356 git_iterator * target ,
@@ -2363,10 +2383,7 @@ static int checkout_data_init(
23632383
23642384 if (!data -> opts .target_directory )
23652385 data -> opts .target_directory = git_repository_workdir (repo );
2366- else if (!git_path_isdir (data -> opts .target_directory ) &&
2367- (error = checkout_mkdir (data ,
2368- data -> opts .target_directory , NULL ,
2369- GIT_DIR_MODE , GIT_MKDIR_VERIFY_DIR )) < 0 )
2386+ else if ((error = validate_target_directory (data )) < 0 )
23702387 goto cleanup ;
23712388
23722389 if ((error = git_repository_index (& data -> index , data -> repo )) < 0 )
0 commit comments