Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
707 B
1
Indexable
Never
import sublime
import sublime_plugin
import subprocess
import os

class AutoPullOnLoad(sublime_plugin.EventListener):
    def on_load_async(self, view):
        file_path = view.file_name()
        if file_path:
            repo_path = self.find_git_root(file_path)
            if repo_path:
                self.git_pull(repo_path)

    def find_git_root(self, path):
        while path:
            if os.path.isdir(os.path.join(path, '.git')):
                return path
            parent = os.path.dirname(path)
            if parent == path:
                break
            path = parent
        return None

    def git_pull(self, repo_path):
        subprocess.run(["git", "pull"], cwd=repo_path)
Leave a Comment