Updated (sync.py)
This commit is contained in:
parent
97542fc5d8
commit
54eae258a2
29
sync.py
29
sync.py
|
@ -4,19 +4,11 @@ def run_command(command):
|
||||||
result = subprocess.run(command, shell=True, text=True, capture_output=True)
|
result = subprocess.run(command, shell=True, text=True, capture_output=True)
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
def get_largest_diff_file():
|
def get_first_alphabetical_diff():
|
||||||
diff_stats = run_command("git diff --numstat").splitlines()
|
# Get the list of modified files
|
||||||
largest_diff = 0
|
modified_files = run_command("git diff --name-only").splitlines()
|
||||||
largest_file = ""
|
# Return the first file in alphabetical order if there are any modified files, otherwise return None
|
||||||
for line in diff_stats:
|
return sorted(modified_files)[0] if modified_files else None
|
||||||
parts = line.split()
|
|
||||||
if len(parts) >= 3:
|
|
||||||
added, deleted, filename = parts[0], parts[1], parts[2]
|
|
||||||
total_changes = int(added) + int(deleted)
|
|
||||||
if total_changes > largest_diff:
|
|
||||||
largest_diff = total_changes
|
|
||||||
largest_file = filename
|
|
||||||
return largest_file
|
|
||||||
|
|
||||||
def has_remote_changes():
|
def has_remote_changes():
|
||||||
subprocess.run("git fetch", shell=True) # Ensure we have the latest info
|
subprocess.run("git fetch", shell=True) # Ensure we have the latest info
|
||||||
|
@ -24,18 +16,19 @@ def has_remote_changes():
|
||||||
return "Your branch is behind" in status
|
return "Your branch is behind" in status
|
||||||
|
|
||||||
def has_local_changes():
|
def has_local_changes():
|
||||||
status = run_command("git status")
|
# Instead of checking for the presence of changes, return the first file that has been changed
|
||||||
return "nothing to commit" not in status
|
return get_first_alphabetical_diff()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
first_diff = has_local_changes()
|
||||||
if has_remote_changes():
|
if has_remote_changes():
|
||||||
print("Pulling changes...")
|
print("Pulling changes...")
|
||||||
run_command("git pull")
|
run_command("git pull")
|
||||||
elif has_local_changes():
|
elif first_diff:
|
||||||
print("Adding and committing local changes...")
|
print("Adding and committing local changes...")
|
||||||
run_command("git add .")
|
run_command("git add .")
|
||||||
largest_diff_file = get_largest_diff_file()
|
# Use the first differing file in the commit message
|
||||||
commit_message = f'Updated {largest_diff_file}' if largest_diff_file else "commit"
|
commit_message = f'Updated ({first_diff})'
|
||||||
run_command(f'git commit -S -m "{commit_message}"')
|
run_command(f'git commit -S -m "{commit_message}"')
|
||||||
run_command("git push")
|
run_command("git push")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue