PK!git_gone/__init__.pyPK!ᚖgit_gone/__main__.pyfrom argparse import ArgumentParser from .install import install, uninstall from .read_changes import read_changes def main(): parser = ArgumentParser() subparsers = parser.add_subparsers(dest="command") subparsers.required = True install_parser = subparsers.add_parser("install") install_parser.set_defaults(handler=install) uninstall_parser = subparsers.add_parser("uninstall") uninstall_parser.set_defaults(handler=uninstall) changes_parser = subparsers.add_parser("changes") changes_parser.set_defaults(handler=read_changes) args = parser.parse_args() args.handler() if __name__ == "__main__": main() PK!git_gone/data/__init__.pyPK!cKs1$git_gone/data/track-changed-repos.sh#!/usr/bin/env bash file="$HOME/.modified"; # Create tracker file if it doesn't exist if ! [[ -r $file ]]; then touch $file; fi; track_changed_git_repos() { if git -C "$PWD" rev-parse; then # Only append line if doesn't already exist if ! $(grep -xq "$PWD" "$file"); then echo $PWD >> $file; fi; fi; } chpwd() { (track_changed_git_repos >/dev/null 2>&1 &) } alias leave="git-gone changes && shutdown -c now"PK!#%git_gone/install.pyfrom pathlib import Path THIS_PATH = Path(__file__) SCRIPT_PATH = THIS_PATH.parent / "data" / "track-changed-repos.sh" ZSHRC_PATH = Path.home() / ".zshrc" SOURCE_LINE = f". {SCRIPT_PATH}" def install(): with open(ZSHRC_PATH, "a") as f: f.write(f"\n{SOURCE_LINE}\n") def uninstall(): text = ZSHRC_PATH.read_text() ZSHRC_PATH.write_text( text.replace(SOURCE_LINE, '') )PK! git_gone/read_changes.pyfrom pathlib import Path from plumbum import cmd, local, ProcessExecutionError, RETCODE MODIFIED_PATH = Path.home() / ".modified" MODIFIED_PATH.touch() def count_unpushed_commits() -> int: """Determine the number of unpushed commits for the cwd. :return: """ branch_ref = cmd.git("symbolic-ref", "-q", "HEAD").strip() if not branch_ref: return False branch_origin = cmd.git("for-each-ref", "--format='%(upstream:short)'", branch_ref).strip().replace("'", '') if not branch_origin: return False assert branch_ref.startswith("refs/heads/") branch = branch_ref[len("refs/heads/"):] return int(cmd.git("rev-list", f"{branch_origin}..{branch}", "--count").strip()) def has_uncommitted_changes() -> bool: """Determine whether there are any uncommitted changes in the cwd. :return: """ retcode = cmd.git["diff", "--no-ext-diff", "--quiet", "--exit-code"] & RETCODE return retcode == 1 def yes_no_response(query: str, default_response: bool = True) -> bool: """Prompt user with a yes / no response for a given query string. :param query: query string :param default_response: default return value if user input invalid :return: """ default_string = "Y/n" if default_response else "y/N" response = input(f"{query} [{default_string}] ").lower().strip() if response in ("y", "yes"): return True elif response in ("n", "no"): return False return default_response def read_changes(): for path_str in MODIFIED_PATH.read_text().splitlines(): path = Path(path_str) if not path.exists(): continue try: with local.cwd(path): if has_uncommitted_changes(): should_commit = yes_no_response(f"{path} has uncommitted changes, do you want to commit them?") if should_commit: message = input( "Enter commit message (leave blank for default): ") or "Default git-gone commit message." cmd.git("commit", "-am", message) if count_unpushed_commits(): should_push = yes_no_response(f"{path} has unpushed commits, do you want to push them?") if should_push: print("Pushing commits...") cmd.git("push") # Clear modified file MODIFIED_PATH.write_text("") except ProcessExecutionError: continue PK!Hx!/3)git_gone-0.1.5.dist-info/entry_points.txtN+I/N.,()J,MK2A ̼x+PK!HڽTUgit_gone-0.1.5.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HJZ!git_gone-0.1.5.dist-info/METADATAOO@sԤݶlH4P}ij[ ީƛ\6;o޼_f^‹ Scy$4r'4km Z {0t[#xcj:[Q|^9屄GbkeBhJ(*$PXM\eZJ4]43VHRy: [FTHc9B8R//4X`fꚆwZ;C~{'wg3(.YHI̓q XnXƲΩB>y3iZ'TӲFZAa?Ӻ[R=\1|Psh렷AdA<:"w,|^pXy/PK!H git_gone-0.1.5.dist-info/RECORDιr@[P@Iha,.$)ԥohQe J7lZzcU#N;b_ P]+i帬 @%mw ^i6:, k92KE_JJybw L/d=x:r*-\7ZNR|R"/?l0um2"[q*Z4 e5lZ7x?)ԐkgOJ3>Nmd6m;{Oc%,1s}9"Òu-D3d&M`4P\zRm5D| \@Is?}GT>R]֭9#ΥzlF:\QuXӵX_0G mw: ^4%Gd uz PK!git_gone/__init__.pyPK!ᚖ2git_gone/__main__.pyPK!git_gone/data/__init__.pyPK!cKs1$1git_gone/data/track-changed-repos.shPK!#%git_gone/install.pyPK! git_gone/read_changes.pyPK!Hx!/3)git_gone-0.1.5.dist-info/entry_points.txtPK!HڽTU~git_gone-0.1.5.dist-info/WHEELPK!HJZ!git_gone-0.1.5.dist-info/METADATAPK!H git_gone-0.1.5.dist-info/RECORDPK