@@ -63,21 +63,40 @@ def trial(src, dst):
6363 return subprocess .run ([sys .executable , "-m" , "pytest" , "-q" ], cwd = copy ).returncode
6464
6565
66+ def sync_commit (src , dst ):
67+ """Copy and commit shared files only when the target checkout is clean."""
68+ status = subprocess .run (["git" , "-C" , dst , "status" , "--porcelain" ],
69+ check = True , capture_output = True , text = True ).stdout
70+ if status :
71+ raise RuntimeError ("The sister checkout must be clean before synchronization" )
72+ todo = sync (src , dst )
73+ if todo :
74+ subprocess .run (["git" , "-C" , dst , "add" , "--" , * todo ], check = True )
75+ subprocess .run (["git" , "-C" , dst , "-c" , "commit.gpgsign=false" , "commit" ,
76+ "-m" , "Sync shared explorer files" ], check = True )
77+ return todo
78+
79+
6680def main ():
6781 ap = argparse .ArgumentParser (description = __doc__ .splitlines ()[0 ])
6882 ap .add_argument ("target" , help = "root of the repository to update" )
6983 mode = ap .add_mutually_exclusive_group ()
7084 mode .add_argument ("--check" , action = "store_true" , help = "report differences, change nothing" )
7185 mode .add_argument ("--test" , action = "store_true" ,
7286 help = "run the target's tests with these shared files, change nothing" )
87+ mode .add_argument ("--commit" , action = "store_true" ,
88+ help = "copy shared files and commit them in a clean target checkout" )
7389 args = ap .parse_args ()
7490 src = os .path .dirname (os .path .abspath (__file__ ))
7591 if not os .path .exists (os .path .join (args .target , "config.py" )):
7692 sys .exit (f"{ args .target } has no config.py; create it before syncing." )
7793 if args .test :
7894 sys .exit (trial (src , args .target ))
7995
80- todo = stale (src , args .target ) if args .check else sync (src , args .target )
96+ if args .commit :
97+ todo = sync_commit (src , args .target )
98+ else :
99+ todo = stale (src , args .target ) if args .check else sync (src , args .target )
81100 for p in todo :
82101 print (("differs: " if args .check else "copied: " ) + p )
83102 if not todo :
0 commit comments