diff -ur v14/fsyn.py v15/fsyn.py --- v14/fsyn.py 2021-09-13 21:11:19.000000000 +0900 +++ v15/fsyn.py 2021-10-02 15:08:45.000000000 +0900 @@ -289,7 +289,7 @@ cmp = get_cmp( id, targ_id ) if cmp.rm: cmd = '( cd {} ; rm -f {} )'.format( dir_path, to_str( cmp.rm, delim=' ' ) ) - cmd_call( cmd ) + cmd_call( cmd ) set_curr( targ_id ) @@ -323,6 +323,9 @@ return # targ_id is not child + restore_id( targ_id ) + set_curr( targ_id ) + return else: # dirty msg = 'dirty from curr {}. checkout {} ?'.format( curr_cmp.id_old, id ) @@ -658,19 +661,8 @@ return id - def restore( path='' ): - if not path: - curr_cmp = get_curr_cmp() - if curr_cmp.same: - dbg.out( 'clean id={}'.format( get_curr() ) ) - return - rm_chg = cmp.rm + cmp.chg - dbg.out( 'rm_chg {}'.format( '\n'.join( rm_chg ) ) ) - for path in rm_chg: - restore( path ) - return - - #dbg.out( 'restore {}'.format( path ) ) + def restore_path( path ): + dbg.out( 'restore {}'.format( path ) ) id = get_curr() id = get_id_inc_id_path( id, path ) @@ -688,6 +680,28 @@ #dbg.out( 'cmd={}'.format( cmd ) ) cmd_call( cmd ) + def restore_id( id ): + cmp = get_cmp( id, 'now' ) + if cmp.is_same(): + dbg.out( 'clean id={}'.format( id ) ) + return + + rm_chg = cmp.rm + cmp.chg + dbg.out( 'rm_chg {}'.format( '\n'.join( rm_chg ) ) ) + for path in rm_chg: + restore_path( path ) + + dbg.out( 'add {}'.format( '\n'.join( cmp.add ) ) ) + if cmp.add: + cmd = '( cd {} ; rm -f {} )'.format( dir_path, to_str( cmp.add, delim=' ' ) ) + cmd_call( cmd ) + + def restore( path='' ): + if path: + restore_path( path ) + else: + id = get_curr() + restore_id( id ) return empty.new( locals() )