Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ap_git/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,25 @@ def fetch_remote(self, remote: str, force: bool = False,
subprocess.run(cmd, cwd=self.__local_path, shell=False)

def __branch_create(self, branch_name: str,
start_point: str = None) -> None:
start_point: str = None,
force: bool = False) -> None:
"""
Create a new branch starting from a given commit.

Parameters:
branch_name (str): Name of the branch to create
start_point (str): Starting commit or branch (optional)
force (bool): Force creation, resetting the branch tip if it
already exists (default is False)
"""
if branch_name is None:
raise ValueError("branch_name is required, cannot be None.")

cmd = ['git', 'branch', branch_name]

if force:
cmd.append('-f')

if start_point:
if not self.__is_commit_present_locally(commit_ref=start_point):
raise ex.CommitNotFoundError(commit_ref=start_point)
Expand Down Expand Up @@ -626,7 +632,7 @@ def shallow_clone_at_commit_from_local(source: str,
# as shallow clone needs a branch
temp_branch_name = "temp-b-" + commit_id
source_repo.__branch_create(
branch_name=temp_branch_name, start_point=commit_id
branch_name=temp_branch_name, start_point=commit_id, force=True
)

# perform the clone from the source repository
Expand Down
Loading