feat(git): all needed subcommands (commit, branches, push, pull)

This commit is contained in:
2026-04-10 08:58:17 +02:00
parent 6e497fdfd2
commit 6018d6256d

View File

@@ -1,5 +1,105 @@
import os
import subprocess
def init(dirname: str):
subprocess.call("git init", cwd=dirname)
def init(dirname: str) -> bool:
"""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