in generate/util.py [0:0]
def push_folder_to_git(repo_path, remote_url, branch_name="main"):
"""Pushes the contents of an existing folder to a Git repository.
Args:
repo_path: Local path to the folder (already initialized as a Git repository).
remote_url: The URL of the remote git repository (e.g., "https://github.com/your-username/your-repo.git").
branch_name: The branch to push to (defaults to "main").
"""
repo = Repo.init(repo_path)
if branch_name not in repo.heads:
repo.git.checkout("-b", branch_name)
else:
repo.heads[branch_name].checkout()
# Add, commit, and push changes
repo.git.add(all=True, force=True)
repo.index.commit("eztf auto commit")
# Add remote
if "origin" not in repo.remotes:
repo.create_remote("origin", remote_url)
origin = repo.remotes.origin
r = re.compile(r"refs/tags/0\.(\d+)-auto")
max_tag = 0
# below command returns
# 0206504b3460ac4e63e28461c525a3708f20a960 refs/tags/0.1-auto
rem_tag = repo.git.ls_remote("--tags", "origin", "0.*-auto").strip()
for tagline in rem_tag.split("\n"):
tagl = tagline.strip().split()
if len(tagl) < 2:
continue
if match := r.match(tagl[1].strip()):
curr_tag = int(match.group(1))
max_tag = max(curr_tag, max_tag)
max_tag += 1
tag = f"0.{max_tag}-auto"
repo.create_tag(tag)
print(f"pushing branch {branch_name} & tag {tag} to {remote_url}")
origin.push(
refspec=[f"{branch_name}:{branch_name}", f"{tag}:{tag}"],
force=True,
atomic=True,
)
print("Successfully pushed to Remote Git")