Skip to content
Merged
Show file tree
Hide file tree
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
51 changes: 51 additions & 0 deletions clony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from clony.internals.checkout import restore_files, switch_branch_or_commit
from clony.internals.commit import make_commit
from clony.internals.log import display_commit_logs, parse_commit_object
from clony.internals.merge import perform_merge
from clony.internals.reset import reset_head, validate_commit_reference
from clony.internals.staging import stage_file
from clony.internals.status import get_status
Expand Down Expand Up @@ -643,3 +644,53 @@ def checkout(target: str, paths: tuple, force: bool):
if not switch_branch_or_commit(target, force):
logger.error("Checkout failed.")
sys.exit(1)


# Merge command to perform a three-way merge with the current branch
@cli.command()
@click.argument("base", required=True)
@click.argument("other", required=True)
def merge(base: str, other: str):
"""Perform a three-way merge with the current branch.

Merge changes from BRANCH or COMMIT into the current branch, with BASE
as the common ancestor. Conflicts will be displayed in a tabular format
for manual resolution.
"""

try:
# Validate the commits
if not validate_commit_reference(base):
# Log the error and exit
logger.error(f"Invalid base commit: {base}")
sys.exit(1)

if not validate_commit_reference(other):
# Log the error and exit
logger.error(f"Invalid other commit: {other}")
sys.exit(1)

# Perform the merge
conflicts = perform_merge(base, other)

# Exit with a status code indicating if there were conflicts
if conflicts > 0:
# Log the warning
logger.warning(
f"Merge completed with {conflicts} conflict(s). "
f"Manual resolution required."
)

# Exit with a status code of 1
sys.exit(1)
else:
# Log the info
logger.info("Merge completed successfully with no conflicts.")

# Exit with a status code of 0
sys.exit(0)

except Exception as e:
# Log the error and exit
logger.error(f"Error performing merge: {str(e)}")
sys.exit(1)
2 changes: 2 additions & 0 deletions clony/internals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from clony.internals.checkout import restore_files, switch_branch_or_commit
from clony.internals.commit import make_commit
from clony.internals.log import display_commit_logs, get_commit_logs
from clony.internals.merge import perform_merge
from clony.internals.reset import reset_head
from clony.internals.staging import stage_file
from clony.internals.status import FileStatus, get_status
Expand All @@ -23,4 +24,5 @@
"display_commit_logs",
"switch_branch_or_commit",
"restore_files",
"perform_merge",
]
Loading