1
Fork 0

Add simple-git-push script.

This commit is contained in:
Bauke 2022-10-01 12:51:53 +02:00
parent 3a17571bdd
commit cb899efa7f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 44 additions and 0 deletions

View File

@ -14,6 +14,7 @@ alias gd="git diff"
alias gdc="git diff --cached"
alias gl="git log"
alias gls="git log --all --decorate --oneline --graph"
alias gp="simple-git-push"
alias gs="git status"
alias clipboard-to-file="xclip -sel clip -o > $1"

43
.local/bin/simple-git-push Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
import argparse
import subprocess
import sys
import typing
def main() -> None:
available_remotes = git_remote()
if len(available_remotes) == 0:
print("No remotes found")
sys.exit(0)
# Parse any extra arguments passed to use them in git_push, this way
# simple-git-push acts like an aliased command.
extra_args = argparse.ArgumentParser(add_help=False).parse_known_args()[1]
remotes_to_push = ["origin", "github"]
for remote in available_remotes:
if remote in remotes_to_push:
git_push(remote, extra_args)
def git_remote() -> typing.List[str]:
"""Run `git remote` and return found remote names."""
command = ["git", "remote"]
output = subprocess.run(command, capture_output=True, encoding="utf8")
return output.stdout.splitlines()
def git_push(remote: str, extra_args: typing.List[str]) -> None:
"""Run `git push` for the given remote."""
command = ["git", "push", "--follow-tags", remote, *extra_args]
print(f"""Pushing: {" ".join(command)}""")
subprocess.run(command)
if __name__ == "__main__":
main()