Skip to content

Commit fb3dc84

Browse files
authored
Add check for local changes while checkout
1 parent 3f89c49 commit fb3dc84

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mlc/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,18 @@ def pull_repo(self, repo_url, branch=None, checkout = None):
12721272
subprocess.run(clone_command, check=True)
12731273

12741274
else:
1275-
logger.info(f"Repository {repo_name} already exists at {repo_path}. Pulling latest changes...")
1276-
subprocess.run(['git', '-C', repo_path, 'pull'], check=True)
1275+
logger.info(f"Repository {repo_name} already exists at {repo_path}. Checking for local changes...")
1276+
1277+
# Check for local changes
1278+
status_command = ['git', '-C', repo_path, 'status', '--porcelain']
1279+
local_changes = subprocess.run(status_command, capture_output=True, text=True)
1280+
1281+
if local_changes.stdout:
1282+
logger.warning("There are local changes in the repository. Please commit or stash them before checking out.")
1283+
return {"return": 1, "error": f"Local changes detected in the already existing repository: {repo_path}"}
1284+
else:
1285+
logger.info("No local changes detected. Fetching latest changes...")
1286+
subprocess.run(['git', '-C', repo_path, 'fetch'], check=True)
12771287

12781288
# Checkout to a specific branch or commit if --checkout is provided
12791289
if checkout:

0 commit comments

Comments
 (0)