Skip to content

Commit

Permalink
Merge pull request #80 from anandhu-eng/dev
Browse files Browse the repository at this point in the history
Add check for local changes while checkout
  • Loading branch information
arjunsuresh authored Feb 11, 2025
2 parents 602feaa + fb3dc84 commit 5a3d67a
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit 5a3d67a

Please sign in to comment.