feat(git): all needed subcommands (commit, branches, push, pull)
This commit is contained in:
@@ -1,5 +1,105 @@
|
|||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def init(dirname: str):
|
def init(dirname: str) -> bool:
|
||||||
subprocess.call("git init", cwd=dirname)
|
"""Initialize a new git repo in the directory
|
||||||
|
|
||||||
|
Args:
|
||||||
|
dirname: The directory to create it in
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
return subprocess.call("git init", cwd=dirname) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def commit(msg: str):
|
||||||
|
"""Create a new commit
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg: The commit message
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call('git commit -am "' + msg + '"', cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def branch_add(name: str):
|
||||||
|
"""Create a new git branch
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: The name of the branch to create
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git branch " + name, cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def branch_switch(name: str):
|
||||||
|
"""Switch to a git branch
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: The name of the branch to switch to
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git checkout " + name, cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def branch_show():
|
||||||
|
"""Create a new git branch
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: The name of the branch to create
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git branch", cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def branch_delete(name: str):
|
||||||
|
"""Delete a git branch
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: The name of the branch to delete
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git branch -d " + name, cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def pull(rebase: bool = False):
|
||||||
|
"""Pull git changes
|
||||||
|
|
||||||
|
Args:
|
||||||
|
rebase: Whether to rebase or not
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git pull" + (" --rebase" if rebase else ""), cwd=dir) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def push(force: bool = False):
|
||||||
|
"""Push git changes
|
||||||
|
|
||||||
|
Args:
|
||||||
|
force: Whether to force push
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True on success, False on error
|
||||||
|
"""
|
||||||
|
dir = os.getcwd()
|
||||||
|
return subprocess.call("git push" + (" --force" if force else ""), cwd=dir) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user