2024-04-04 16:40:08 -04:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
def run_command(command):
|
|
|
|
result = subprocess.run(command, shell=True, text=True, capture_output=True)
|
|
|
|
return result.stdout.strip()
|
|
|
|
|
2024-04-04 17:04:41 -04:00
|
|
|
def get_first_alphabetical_diff():
|
|
|
|
# Get the list of modified files
|
|
|
|
modified_files = run_command("git diff --name-only").splitlines()
|
|
|
|
# Return the first file in alphabetical order if there are any modified files, otherwise return None
|
|
|
|
return sorted(modified_files)[0] if modified_files else None
|
2024-04-04 17:00:48 -04:00
|
|
|
|
2024-04-04 16:40:08 -04:00
|
|
|
def has_remote_changes():
|
|
|
|
subprocess.run("git fetch", shell=True) # Ensure we have the latest info
|
|
|
|
status = run_command("git status")
|
|
|
|
return "Your branch is behind" in status
|
|
|
|
|
|
|
|
def has_local_changes():
|
2024-04-04 17:04:41 -04:00
|
|
|
# Instead of checking for the presence of changes, return the first file that has been changed
|
|
|
|
return get_first_alphabetical_diff()
|
2024-04-04 16:40:08 -04:00
|
|
|
|
|
|
|
def main():
|
2024-04-04 17:04:41 -04:00
|
|
|
first_diff = has_local_changes()
|
2024-04-04 16:40:08 -04:00
|
|
|
if has_remote_changes():
|
|
|
|
print("Pulling changes...")
|
|
|
|
run_command("git pull")
|
2024-04-04 17:04:41 -04:00
|
|
|
elif first_diff:
|
2024-04-04 16:40:08 -04:00
|
|
|
print("Adding and committing local changes...")
|
|
|
|
run_command("git add .")
|
2024-04-04 17:04:41 -04:00
|
|
|
# Use the first differing file in the commit message
|
|
|
|
commit_message = f'Updated ({first_diff})'
|
2024-04-04 17:00:48 -04:00
|
|
|
run_command(f'git commit -S -m "{commit_message}"')
|
2024-04-04 16:40:08 -04:00
|
|
|
run_command("git push")
|
|
|
|
else:
|
|
|
|
print("No changes to update.")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|