refactor: elimino funciones no usadas de modulo git
This commit is contained in:
-120
@@ -1,6 +1,4 @@
|
|||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
|
|
||||||
from lib.io import *
|
from lib.io import *
|
||||||
|
|
||||||
@@ -9,58 +7,6 @@ CHANGELOG_FILE = "CHANGELOG.md"
|
|||||||
UPDATED_CHANGELOG_MSG = "Updated " + CHANGELOG_FILE
|
UPDATED_CHANGELOG_MSG = "Updated " + CHANGELOG_FILE
|
||||||
|
|
||||||
|
|
||||||
def branch_exists(branch):
|
|
||||||
return os.path.isfile(os.path.join(".git", "refs", "heads", branch))
|
|
||||||
|
|
||||||
|
|
||||||
def get_current_branch():
|
|
||||||
output = os.popen("git rev-parse --abbrev-ref HEAD").readline()
|
|
||||||
output = output.strip()
|
|
||||||
|
|
||||||
return None if output == "HEAD" else output
|
|
||||||
|
|
||||||
|
|
||||||
def is_repository():
|
|
||||||
return os.path.isdir(".git")
|
|
||||||
|
|
||||||
|
|
||||||
def flow_config(name: str, value: str | None = None) -> str | None:
|
|
||||||
if value is None:
|
|
||||||
value = os.popen(f"git config --file {FLOWCONFIG_FILE} '{name}'").readline()
|
|
||||||
return value.strip()
|
|
||||||
else:
|
|
||||||
os.popen(f"git config --file {FLOWCONFIG_FILE} '{name}' '{value}'").close()
|
|
||||||
|
|
||||||
|
|
||||||
def config(name: str, value: str | None = None, **kwargs) -> str | None:
|
|
||||||
options = []
|
|
||||||
|
|
||||||
for k in kwargs:
|
|
||||||
value = kwargs[k]
|
|
||||||
k = k.replace("_", "-")
|
|
||||||
|
|
||||||
if isinstance(value, bool):
|
|
||||||
options.append("--" + k if value else "--no-" + k)
|
|
||||||
else:
|
|
||||||
options.append(f"--{k}={value}")
|
|
||||||
|
|
||||||
options = " ".join(options)
|
|
||||||
|
|
||||||
if value is None:
|
|
||||||
return os.popen(f"git config {options} '{name}'").readline().strip()
|
|
||||||
else:
|
|
||||||
os.popen(f"git config {options} '{name}' '{value}'").close()
|
|
||||||
|
|
||||||
|
|
||||||
def create_branch(name, base: str | None = None, switch: bool = False):
|
|
||||||
command = "switch -c" if switch else "branch"
|
|
||||||
os.popen(f"git {command} '{name}'" + (f" '{base}'" if base is not None else ""))
|
|
||||||
|
|
||||||
|
|
||||||
def get_remotes():
|
|
||||||
return os.popen("git remote").readlines()
|
|
||||||
|
|
||||||
|
|
||||||
class Status:
|
class Status:
|
||||||
worktree: str
|
worktree: str
|
||||||
index: str
|
index: str
|
||||||
@@ -71,72 +17,6 @@ class Status:
|
|||||||
self.index = line[1]
|
self.index = line[1]
|
||||||
self.file = line[3:].strip("\n")
|
self.file = line[3:].strip("\n")
|
||||||
|
|
||||||
|
|
||||||
def status():
|
|
||||||
status: list[Status] = []
|
|
||||||
lines = os.popen("git status --porcelain").readlines()
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
status.append(Status(line))
|
|
||||||
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
def switch(branch: str = "-"):
|
|
||||||
os.popen(f"git switch '{branch}'").close()
|
|
||||||
|
|
||||||
|
|
||||||
def rename_branch(oldbranch: str, newbranch):
|
|
||||||
os.popen(f"git branch -m '{oldbranch}' '{newbranch}'").close()
|
|
||||||
|
|
||||||
|
|
||||||
def _command_list_as_str(cmd: list[str]) -> str:
|
|
||||||
s = []
|
|
||||||
|
|
||||||
for arg in cmd:
|
|
||||||
arg = ('"' + arg + '"') if " " in arg else arg
|
|
||||||
s.append(arg)
|
|
||||||
|
|
||||||
return " ".join(s)
|
|
||||||
|
|
||||||
|
|
||||||
def _run_command(git_subcommand: str, *args, **kwargs) -> subprocess.CompletedProcess:
|
|
||||||
cmd = ["git", git_subcommand]
|
|
||||||
|
|
||||||
for k in kwargs:
|
|
||||||
value = kwargs[k]
|
|
||||||
k = k.replace("_", "-")
|
|
||||||
|
|
||||||
if isinstance(value, bool):
|
|
||||||
cmd.append("--" + k if value else "--no-" + k)
|
|
||||||
else:
|
|
||||||
if len(k) == 1:
|
|
||||||
cmd.append("-" + k)
|
|
||||||
else:
|
|
||||||
cmd.append("--" + k)
|
|
||||||
|
|
||||||
cmd.append(value)
|
|
||||||
|
|
||||||
cmd += args
|
|
||||||
|
|
||||||
print(f"> Running: " + _command_list_as_str(cmd))
|
|
||||||
|
|
||||||
return subprocess.run(cmd, capture_output=True, text=True)
|
|
||||||
|
|
||||||
|
|
||||||
def output(git_subcommand: str, *args, **kwargs) -> list[str] | None:
|
|
||||||
completed_process = _run_command(git_subcommand, *args, **kwargs)
|
|
||||||
|
|
||||||
if completed_process.returncode == 0:
|
|
||||||
return list(filter(lambda l: l, str(completed_process.stdout).splitlines()))
|
|
||||||
else:
|
|
||||||
for line in str(completed_process.stderr).splitlines():
|
|
||||||
print("! " + line, file=sys.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
def exec(git_subcommand: str, *args, **kwargs) -> bool:
|
|
||||||
return _run_command(git_subcommand, *args, **kwargs).returncode == 0
|
|
||||||
|
|
||||||
class Git:
|
class Git:
|
||||||
FLOWCONFIG_FILE = ".flowconfig"
|
FLOWCONFIG_FILE = ".flowconfig"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user