def update_external(self, url, revision): """Update working dir using a local directory. :param url: path to the repository :type url: str :param revision: ignored :type revision: None """ # Expand env variables and ~ url = os.path.expandvars(os.path.expanduser(url)) if os.path.isdir(self.working_dir): old_commit = get_filetree_state(self.working_dir) else: old_commit = "" ignore_list = [] if os.path.isdir(os.path.join(url, ".git")): # It seems that this is a git repository. Get the list of files to # ignore try: g = GitRepository(working_tree=url) ignore_list = g.git_cmd( [ "ls-files", "-o", "--ignored", "--exclude-standard", "--directory", ], output=PIPE, ).out ignore_list = [ "/%s" % l.strip().rstrip("/") for l in ignore_list.splitlines() ] logger.debug("Ignore in external: %s", ignore_list) except Exception: # don't crash on exception pass sync_tree( url, self.working_dir, preserve_timestamps=False, delete_ignore=True, ignore=list(VCS_IGNORE_LIST) + ignore_list, ) new_commit = get_filetree_state(self.working_dir) if new_commit == old_commit: return ReturnValue.unchanged, old_commit, new_commit else: return ReturnValue.success, old_commit, new_commit
def add_dir(self, path: str) -> None: """Add a file tree to the fingerprint. :param path: a path to a directory """ assert os.path.isdir(path), "directory %s does not exist" % path self.elements[os.path.basename(path)] = get_filetree_state(path)
def add_dir(self, path: str) -> None: """Add a file tree to the fingerprint. :param path: a path to a directory """ if os.path.isdir(path): self.elements[os.path.abspath(path)] = get_filetree_state(path) else: self.elements[os.path.abspath(path)] = ""
def update_external( self, url: str, revision: Optional[str] ) -> tuple[ReturnValue, str, str]: """Update working dir using a local directory. :param url: path to the repository :param revision: ignored If <url>/.git is a directory then git ls-files will be called to get the list of files to ignore. """ if os.path.isdir(self.working_dir): old_commit = get_filetree_state(self.working_dir) else: old_commit = "" ignore_list: list[str] = [] if which("rsync") and "use-rsync" in os.environ.get( "E3_ENABLE_FEATURE", "" ).split(","): # Run rsync using -a but without preserving timestamps. --update switch # is also used to skip files that are older in the user directory than # in the checkout itself. This ensure rsync remain efficient event when # timestamps are not preserved (otherwise rsync has to compute checksum # of all file as quick check cannot be used when timestamp is not # preserved). rsync_cmd = [ "rsync", "--update", "-rlpgoD", f"{unixpath(url)}/", f"{unixpath(self.working_dir)}", "--delete-excluded", ] + [f"--exclude={el}" for el in VCS_IGNORE_LIST] if os.path.isdir(os.path.join(url, ".git")) and os.path.isfile( os.path.join(url, ".gitignore") ): rsync_cmd.append("--filter=:- .gitignore") p = Run(rsync_cmd, cwd=url, output=None) if p.status != 0: raise e3.error.E3Error("rsync failed") else: if os.path.isdir(os.path.join(url, ".git")): # It seems that this is a git repository. Get the list of files to # ignore try: g = GitRepository(working_tree=url) ignore_list_lines = g.git_cmd( [ "ls-files", "-o", "--ignored", "--exclude-standard", "--directory", ], output=PIPE, ).out ignore_list = [ f"/{f.strip().rstrip('/')}" for f in ignore_list_lines.splitlines() ] logger.debug("Ignore in external: %s", ignore_list) except Exception: # defensive code # don't crash on exception pass sync_tree( url, self.working_dir, preserve_timestamps=False, delete_ignore=True, ignore=list(VCS_IGNORE_LIST) + ignore_list, ) new_commit = get_filetree_state(self.working_dir) if new_commit == old_commit: return ReturnValue.unchanged, old_commit, new_commit else: return ReturnValue.success, old_commit, new_commit