Skip to content

Instantly share code, notes, and snippets.

@M-Porter
Last active October 1, 2021 21:57
Show Gist options
  • Select an option

  • Save M-Porter/9c4717a7c645e256e97c4f1377d4554b to your computer and use it in GitHub Desktop.

Select an option

Save M-Porter/9c4717a7c645e256e97c4f1377d4554b to your computer and use it in GitHub Desktop.

Revisions

  1. M-Porter revised this gist Oct 1, 2021. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions git-pt
    Original file line number Diff line number Diff line change
    @@ -19,14 +19,12 @@ class PullThis:
    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.
  2. M-Porter revised this gist Oct 1, 2021. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions git-pt
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,11 @@ import subprocess


    class Colors:
    CYAN = '\033[96m'
    GREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    CYAN = "\033[96m"
    GREEN = "\033[92m"
    WARNING = "\033[93m"
    FAIL = "\033[91m"
    ENDC = "\033[0m"


    class PullThis:
  3. M-Porter created this gist Oct 1, 2021.
    55 changes: 55 additions & 0 deletions git-pt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/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()