@@ -38,7 +38,7 @@ IMPORT = sys.argv[2] if len(sys.argv) > 2 else 'import-2.1.x'
3838EXPORT = sys .argv [3 ] if len (sys .argv ) > 3 else 'bugfix-2.1.x'
3939
4040# Get repo paths
41- CI = False
41+ CI = os . environ . get ( 'GITHUB_ACTIONS' ) == 'true'
4242if ACTION == 'CI' :
4343 _REPOS = "."
4444 REPOS = Path (_REPOS )
@@ -68,20 +68,23 @@ if not CONFIGREPO.exists():
6868 sys .exit (1 )
6969
7070# Run git within CONFIGREPO
71- GITSTDERR = None if DEBUG else subprocess .DEVNULL
71+ GITSTDERR = subprocess . PIPE if DEBUG else subprocess .DEVNULL
7272def git (etc ):
73- if DEBUG :
74- print (f"> git { ' ' .join (etc )} " )
75- if etc [0 ] == "push" :
76- info ("*** DRY RUN ***" )
77- return subprocess .run (["echo" ])
78- return subprocess .run (["git" ] + etc , cwd = CONFIGREPO , stdout = subprocess .PIPE , stderr = GITSTDERR )
73+ if DEBUG : print (f"> git { ' ' .join (etc )} " )
74+
75+ result = subprocess .run (["git" ] + etc , cwd = CONFIGREPO , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
76+
77+ if result .returncode != 0 :
78+ print (f"Git command failed: git { ' ' .join (etc )} " )
79+ print (f"Error output: { result .stderr } " )
80+
81+ return result
7982
8083# Get the current branch name
8184def branch (): return git (["rev-parse" , "--abbrev-ref" , "HEAD" ])
8285
8386# git add . ; git commit -m ...
84- def commit (msg , who = "." ): git (["add" , who ]) ; return git (["commit" , "-m" , msg ])
87+ def commit (msg , who = "." ): git (["add" , who ]) ; return git (["commit" , "-m" , f'" { msg } "' ])
8588
8689# git checkout ...
8790def checkout (etc ): return git (["checkout" ] + ([etc ] if isinstance (etc , str ) else etc ))
@@ -90,11 +93,7 @@ def checkout(etc): return git(["checkout"] + ([etc] if isinstance(etc, str) else
9093def gitbd (name ): return git (["branch" , "-D" , name ]).stdout
9194
9295# git status --porcelain : to check for changes
93- def changes (): return git (["status" , "--porcelain" ]).stdout .decode ().strip ()
94-
95- # Configure git user
96- git (["config" , "user.email" , "thinkyhead@users.noreply.github.com" ])
97- git (["config" , "user.name" , "Scott Lahteine" ])
96+ def changes (): return git (["status" , "--porcelain" ]).stdout != ""
9897
9998# Stash uncommitted changes at the destination?
10099if changes ():
@@ -179,9 +178,9 @@ if ACTION == "init":
179178 f .writelines (outlines )
180179
181180 # Create a fresh 'WORK' as a copy of 'init-repo' (README, LICENSE, etc.)
182- gitbd ("WORK" )
183- if CI : git ([ "fetch" , " origin", "init-repo" ])
184- checkout ([" init-repo" , "-b" , "WORK" ])
181+ if not CI : gitbd ("WORK" )
182+ REMOTE = " origin" if CI else "upstream"
183+ checkout ([f" { REMOTE } / init-repo" , "-b" , "WORK" ])
185184
186185 # Copy default configurations into the repo
187186 info ("Create configs in default state..." )
@@ -193,7 +192,7 @@ if ACTION == "init":
193192 shutil .copy (TEMPCON / "default" / fn .name , CONFIGCON / relpath )
194193
195194 # DEBUG: Commit the reset for review
196- if DEBUG : commit ("[DEBUG] Create defaults" )
195+ if DEBUG > 1 : commit ("[DEBUG] Create defaults" )
197196
198197 def replace_in_file (fn , search , replace ):
199198 with open (fn , 'r' ) as f : lines = f .read ()
@@ -203,7 +202,7 @@ if ACTION == "init":
203202 replace_in_file (CONFIGREPO / "README.md" , "%VERSION%" , EXPORT .replace ("release-" , "" ))
204203
205204 # Commit all changes up to now; amend if not debugging
206- if DEBUG :
205+ if DEBUG > 1 :
207206 commit ("[DEBUG] Update README.md version" , "README.md" )
208207 else :
209208 git (["add" , "." ])
@@ -234,16 +233,15 @@ if ACTION == "init":
234233 shutil .rmtree (TEMP )
235234
236235 # Push to the remote (if desired)
237- if CI :
238- PUSH_YES = 'Y'
239- else :
236+ PUSH_YES = 'N'
237+ if not CI :
240238 print ()
241239 PUSH_YES = input (f"Push to upstream/{ EXPORT } ? [y/N] " )
242240 print ()
243241
244242 REMOTE = "origin" if CI else "upstream"
245243
246- if PUSH_YES in ('Y' ,'y ' ):
244+ if PUSH_YES . upper () in ('Y' ,'YES ' ):
247245 info ("Push to remote..." )
248246 git (["push" , "-f" , REMOTE , f"WORK:{ EXPORT } " ])
249247
0 commit comments