Last active
October 1, 2021 21:57
-
-
Save M-Porter/9c4717a7c645e256e97c4f1377d4554b to your computer and use it in GitHub Desktop.
git-pt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import subprocess | |
class Colors: | |
CYAN = "\033[96m" | |
GREEN = "\033[92m" | |
WARNING = "\033[93m" | |
FAIL = "\033[91m" | |
ENDC = "\033[0m" | |
class PullThis: | |
def __get_origin(self) -> str: | |
try: | |
return sys.argv[1] | |
except IndexError: | |
return "origin" | |
def __get_branch(self) -> str: | |
branch = subprocess.check_output( | |
["git", "rev-parse", "--abbrev-ref", "head"] | |
).decode("utf-8") | |
return branch.strip() | |
def run(self): | |
"""Pull down the latest commits from the active working branch. | |
>>> git pt | |
Optionally, you can pull down commits from another remote on the | |
current branch by providing an argument. By default, the command will | |
always pull from origin. | |
>>> git pt another-remote | |
""" | |
origin = self.__get_origin() | |
try: | |
branch = self.__get_branch() | |
except subprocess.CalledProcessError: | |
exit(1) | |
print(f"{Colors.GREEN}Pulling down latest...{Colors.ENDC}") | |
print(f"{Colors.CYAN}=>{Colors.ENDC} git pull {origin} {branch}\n") | |
subprocess.run(["git", "pull", origin, branch]) | |
if __name__ == "__main__": | |
PullThis().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment