@@ -367,3 +367,91 @@ fn untracked_directory_and_diff_preserve_colon_children() {
367367 }
368368 }
369369}
370+
371+ #[ test]
372+ fn selected_commit_keeps_colon_paths_literal ( ) {
373+ let repository = Repository :: new ( "colon-commit" ) ;
374+ repository. git ( & [ "config" , "user.name" , "Fixture" ] ) ;
375+ repository. git ( & [ "config" , "user.email" , "fixture@example.invalid" ] ) ;
376+ repository. git ( & [ "config" , "commit.gpgsign" , "false" ] ) ;
377+ for path in PATHS . into_iter ( ) . chain ( [ "unselected.txt" ] ) {
378+ repository. write ( path, "initial\n " ) ;
379+ }
380+ repository. git ( & [ "add" , "--all" ] ) ;
381+ repository. commit ( ) ;
382+
383+ // Selected commit with pathspec-shaped names must not commit `unselected.txt`
384+ // and must reconcile pre-staged colon paths in the real index.
385+ for path in PATHS . into_iter ( ) . chain ( [ "unselected.txt" ] ) {
386+ repository. write ( path, "committed\n " ) ;
387+ }
388+ repository. mutate ( "stage" , & [ "a:b.txt" , ":(exclude)*.txt" ] ) ;
389+ let committed = repository. data (
390+ "git.write" ,
391+ json ! ( {
392+ "operation" : "commit" ,
393+ "message" : "commit colon paths" ,
394+ "paths" : PATHS ,
395+ } ) ,
396+ ) ;
397+ assert_eq ! ( committed[ "exitCode" ] , 0 , "{committed}" ) ;
398+ assert ! ( committed[ "operationError" ] . is_null( ) , "{committed}" ) ;
399+ assert_eq ! (
400+ repository. git( & [
401+ "diff-tree" ,
402+ "--no-commit-id" ,
403+ "--name-only" ,
404+ "-r" ,
405+ "-z" ,
406+ "HEAD"
407+ ] ) ,
408+ ":(exclude)*.txt\0 :(glob)*.txt\0 D:\\ logs\0 a:b.txt\0 "
409+ ) ;
410+ assert_eq ! (
411+ fs:: read_to_string( repository. 0 . join( "unselected.txt" ) ) . unwrap( ) ,
412+ "committed\n "
413+ ) ;
414+ assert_eq ! (
415+ repository. git( & [ "status" , "--porcelain=v1" , "-z" ] ) ,
416+ " M unselected.txt\0 "
417+ ) ;
418+ }
419+
420+ #[ test]
421+ fn stash_push_keeps_colon_paths_literal ( ) {
422+ let repository = Repository :: new ( "colon-stash" ) ;
423+ repository. git ( & [ "config" , "user.name" , "Fixture" ] ) ;
424+ repository. git ( & [ "config" , "user.email" , "fixture@example.invalid" ] ) ;
425+ repository. git ( & [ "config" , "commit.gpgsign" , "false" ] ) ;
426+ for path in PATHS . into_iter ( ) . chain ( [ "unselected.txt" ] ) {
427+ repository. write ( path, "initial\n " ) ;
428+ }
429+ repository. git ( & [ "add" , "--all" ] ) ;
430+ repository. commit ( ) ;
431+
432+ // Selected stash push with pathspec-shaped names must leave `unselected.txt` modified.
433+ for path in PATHS . into_iter ( ) . chain ( [ "unselected.txt" ] ) {
434+ repository. write ( path, "stashed\n " ) ;
435+ }
436+ let stashed = repository. data (
437+ "git.write" ,
438+ json ! ( {
439+ "operation" : "stashPush" ,
440+ "message" : "stash colon paths" ,
441+ "paths" : PATHS ,
442+ } ) ,
443+ ) ;
444+ assert_eq ! ( stashed[ "exitCode" ] , 0 , "{stashed}" ) ;
445+ assert ! ( stashed[ "operationError" ] . is_null( ) , "{stashed}" ) ;
446+ for path in PATHS {
447+ assert_eq ! (
448+ fs:: read_to_string( repository. 0 . join( path) ) . unwrap( ) ,
449+ "initial\n " ,
450+ "{path}"
451+ ) ;
452+ }
453+ assert_eq ! (
454+ fs:: read_to_string( repository. 0 . join( "unselected.txt" ) ) . unwrap( ) ,
455+ "stashed\n "
456+ ) ;
457+ }
0 commit comments