diff --git a/salt/utils/gitfs.py b/salt/utils/gitfs.py index ecd67d977350..bb8bd3266e02 100644 --- a/salt/utils/gitfs.py +++ b/salt/utils/gitfs.py @@ -477,7 +477,7 @@ def __init__( self._cache_basehash, self._cache_basename ) self._cachedir = salt.utils.path.join(self._cache_hash, self._cache_basename) - self._salt_working_dir = salt.utils.path.join(self._cachedir, ".git", ".salt") + self._salt_working_dir = salt.utils.path.join(cache_root, "work", self._cache_full_basename) self._linkdir = salt.utils.path.join( cache_root, "links", self._cache_full_basename ) @@ -494,6 +494,9 @@ def __init__( msg += " Perhaps git is not available." log.critical(msg, exc_info=True) failhard(self.role) + else: + self.verify_auth() + self.setup_callbacks() if not os.path.isdir(self._salt_working_dir): os.makedirs(self._salt_working_dir) @@ -2483,8 +2486,6 @@ def init_remotes( ) if hasattr(repo_obj, "repo"): # Sanity check and assign the credential parameter - repo_obj.verify_auth() - repo_obj.setup_callbacks() if self.opts["__role"] == "minion" and repo_obj.new: # Perform initial fetch on masterless minion repo_obj.fetch() @@ -2566,7 +2567,7 @@ def _remove_cache_dir(self, cache_dir): def _iter_remote_hashes(self): for item in os.listdir(self.cache_root): - if item in ("hash", "refs", "links"): + if item in ("hash", "refs", "links", "work"): continue if os.path.isdir(salt.utils.path.join(self.cache_root, item)): yield item @@ -2645,13 +2646,12 @@ def fetch_remotes(self, remotes=None): if not remotes or (repo.id, name) in remotes or name in remotes: try: # Find and place fetch_request file for all the other branches for this repo - for branch in os.listdir(repo.get_cache_hash()): + repo_work_hash = os.path.split(repo.get_salt_working_dir())[0] + for branch in os.listdir(repo_work_hash): # Don't place fetch request in current branch being updated if branch == repo.get_cache_basename(): continue - branch_salt_dir = salt.utils.path.join( - repo.get_cache_hash(), branch, ".git", ".salt" - ) + branch_salt_dir = salt.utils.path.join(repo_work_hash, branch) fetch_path = salt.utils.path.join( branch_salt_dir, "fetch_request" ) diff --git a/tests/pytests/functional/utils/test_cache.py b/tests/pytests/functional/utils/test_cache.py index 0527a96b880d..98c6946b653b 100644 --- a/tests/pytests/functional/utils/test_cache.py +++ b/tests/pytests/functional/utils/test_cache.py @@ -4,7 +4,7 @@ import salt.utils.files import salt.utils.path -_ROOT_DIR = ( +_DUMMY_FILES = ( "data.txt", "foo.t2", "bar.t3", @@ -15,7 +15,7 @@ def _make_dummy_files(tmp_path): - for full_path in _ROOT_DIR: + for full_path in _DUMMY_FILES: full_path = salt.utils.path.join(tmp_path, full_path) path, _ = os.path.split(full_path) if not os.path.isdir(path): @@ -31,9 +31,8 @@ def _dummy_files_exists(tmp_path): None if some files exists and others are missing """ ret = None - for full_path in _ROOT_DIR: + for full_path in _DUMMY_FILES: full_path = salt.utils.path.join(tmp_path, full_path) - path, _ = os.path.split(full_path) is_file = os.path.isfile(full_path) if ret is None: ret = is_file diff --git a/tests/pytests/unit/pillar/test_git_pillar.py b/tests/pytests/unit/pillar/test_git_pillar.py new file mode 100644 index 000000000000..e69de29bb2d1