Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for local changes while checkout #80

Merged
merged 1 commit into from
Feb 11, 2025
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
14 changes: 12 additions & 2 deletions mlc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,18 @@ def pull_repo(self, repo_url, branch=None, checkout = None):
subprocess.run(clone_command, check=True)

else:
logger.info(f"Repository {repo_name} already exists at {repo_path}. Pulling latest changes...")
subprocess.run(['git', '-C', repo_path, 'pull'], check=True)
logger.info(f"Repository {repo_name} already exists at {repo_path}. Checking for local changes...")

# Check for local changes
status_command = ['git', '-C', repo_path, 'status', '--porcelain']
local_changes = subprocess.run(status_command, capture_output=True, text=True)

if local_changes.stdout:
logger.warning("There are local changes in the repository. Please commit or stash them before checking out.")
return {"return": 1, "error": f"Local changes detected in the already existing repository: {repo_path}"}
else:
logger.info("No local changes detected. Fetching latest changes...")
subprocess.run(['git', '-C', repo_path, 'fetch'], check=True)

# Checkout to a specific branch or commit if --checkout is provided
if checkout:
Expand Down
Loading