-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_auto_upload.py
More file actions
42 lines (38 loc) · 1.34 KB
/
git_auto_upload.py
File metadata and controls
42 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
PROJECT_PATH = r"C:\Users\mursa\PycharmProjects\ai_job"
GIT_PATH = r"C:\Program Files\Git\cmd\git.exe"
class GitAutoUploader(FileSystemEventHandler):
def on_modified(self, event):
if event.is_directory or ".git" in event.src_path:
return
print(f"Detected change in: {event.src_path}")
# Stage files
run_git("add", ".")
# Commit changes (ignore if nothing to commit)
run_git("commit", "-m", "Auto update")
# Push to GitHub
run_git("push", "origin", "main")
def run_git(*args):
result = subprocess.run([GIT_PATH, "-C", PROJECT_PATH] + list(args), capture_output=True, text=True)
if result.returncode != 0:
if "nothing to commit" in result.stderr.lower():
print("Nothing to commit.")
else:
print("❌ Git error:", result.stderr)
else:
print(result.stdout)
if __name__ == "__main__":
print(f"👀 Watching: {PROJECT_PATH}")
event_handler = GitAutoUploader()
observer = Observer()
observer.schedule(event_handler, path=PROJECT_PATH, recursive=True)
observer.start()
try:
while True:
time.sleep(5)
except KeyboardInterrupt:
observer.stop()
observer.join()