From 6018d6256dfed9c47816790b01fca6bb9a8b100c Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Fri, 10 Apr 2026 08:58:17 +0200 Subject: [PATCH] feat(git): all needed subcommands (commit, branches, push, pull) --- commands/util/git.py | 104 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/commands/util/git.py b/commands/util/git.py index d46bda8..2d1775d 100644 --- a/commands/util/git.py +++ b/commands/util/git.py @@ -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