finished repo work
This commit is contained in:
@@ -28,8 +28,6 @@ class GitRepository:
|
||||
self.repo = Repo(repo_path)
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.repo.config_writer().set_value("user", "name", "blog_creator")
|
||||
self.repo.config_writer().set_value("user", "email", "ridgway.infrastructure@gmail.com")
|
||||
|
||||
def clone(self, remote_url, destination_path):
|
||||
"""Clone a Git repository with authentication"""
|
||||
@@ -52,7 +50,7 @@ class GitRepository:
|
||||
def pull(self, remote_name='origin', ref_name='main'):
|
||||
"""Pull updates from a remote repository with authentication"""
|
||||
try:
|
||||
self.repo.remotes[remote_name].pull(ref_name=ref_name)
|
||||
self.repo.remotes[remote_name].pull(ref_name)
|
||||
return True
|
||||
except GitCommandError as e:
|
||||
print(f"Pulling failed: {e}")
|
||||
@@ -63,15 +61,15 @@ class GitRepository:
|
||||
return [branch.name for branch in self.repo.branches]
|
||||
|
||||
|
||||
def create_branch(self, branch_name, remote_name='origin', ref_name='main'):
|
||||
def create_and_switch_branch(self, branch_name, remote_name='origin', ref_name='main'):
|
||||
"""Create a new branch in the repository with authentication."""
|
||||
try:
|
||||
# Use the same remote and ref as before
|
||||
self.repo.git.branch(branch_name)
|
||||
return True
|
||||
except GitCommandError as e:
|
||||
print(f"Failed to create branch: {e}")
|
||||
return False
|
||||
except GitCommandError:
|
||||
print("Branch already exists switching")
|
||||
# ensure remote commits are pulled into local
|
||||
self.repo.git.checkout(branch_name)
|
||||
|
||||
def add_and_commit(self, message=None):
|
||||
"""Add and commit changes to the repository."""
|
||||
@@ -90,8 +88,9 @@ class GitRepository:
|
||||
return False
|
||||
|
||||
def create_copy_commit_push(self, file_path, title, commit_messge):
|
||||
self.create_branch(title)
|
||||
self.create_and_switch_branch(title)
|
||||
|
||||
self.pull(ref_name=title)
|
||||
shutil.copy(f"{file_path}", f"{self.repo_path}src/content/")
|
||||
|
||||
self.add_and_commit(f"'{commit_messge}'")
|
||||
|
||||
Reference in New Issue
Block a user