Kinda kinda working

This commit is contained in:
decentral1se 2021-07-10 15:35:48 +02:00
parent 78e2674711
commit e906bfa4b1
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 24 additions and 6 deletions

30
tyop.py
View File

@ -37,6 +37,9 @@ class Migration:
self._exit(code=0, output=False)
try:
self.log.info("=" * 79)
self.log.info("RUNNING MIGRATIONS + CHECKS (ONLY GIT LOCAL CHANGES)")
self.log.info("=" * 79)
self._run()
except Exception as exception:
self._exit(msg=f"Failed to run migration, saw: {exception}")
@ -138,17 +141,26 @@ class Migration:
def _commit(self):
for path in self.paths:
self.log.debug(f"Running commit logic inside {path}")
self._shell("git --no-pager diff", check=False, cwd=path)
command = "git --no-pager diff"
output = self._shell(command, cwd=path)
if not output:
self.log.debug(f"No changes detected in {path}, continuing...")
continue
self.log.info("=" * 79)
self.log.info(f"{path}")
self.log.info("=" * 79)
self._shell(command, check=False, cwd=path)
if self._confirm() == "s":
self._shell("git checkout .", check=False, cwd=path)
self.log.debug(f"Skipping {path} as requested...")
continue
if not self.commit_msg:
self.commit_msg = self._message()
self._shell("git pull", check=False, cwd=path)
self._shell("git add .", check=False, cwd=path)
self._shell(f"git commit -m '{self.commit_msg}'", check=False, cwd=path)
self._shell("git push", check=False, cwd=path)
@ -177,7 +189,7 @@ class Migration:
return self._confirm(match=match)
def _clean(self, match=None, branch=False):
def _clean(self, match=None, branch=False, pull=False):
if match:
_paths = [Path(match).parent]
else:
@ -188,6 +200,9 @@ class Migration:
self._shell("git checkout .", check=False, cwd=_path)
if pull:
self._shell("git pull --rebase", check=False, cwd=_path)
if branch:
self.log.debug("Checking out the default branch...")
self._shell(
@ -204,7 +219,7 @@ class Migration:
idx = 0
for match in self.matches:
self._clean(match=match, branch=True)
self._clean(match=match, branch=True, pull=True)
with open(match, "r") as handle:
self.log.debug(f"Processing {match}...")
@ -230,7 +245,7 @@ class Migration:
else:
handle.write(migrated)
if idx <= self.DIFF_LIMIT:
if idx < self.DIFF_LIMIT:
if self._diff(match, idx=idx, check=True):
idx += 1
@ -239,6 +254,9 @@ class Migration:
self.log.debug("Finished migrating files...")
self.log.debug("Commencing change commit run...")
self.log.info("=" * 79)
self.log.info("COMMIT AND PUSH (CHANGES APPLIED)")
self.log.info("=" * 79)
self._commit()
self.log.debug("Finished committing changes...")