44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
#!/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()
 |