MCPcopy Index your code
hub / github.com/saltstack/salt / _fetch

Method _fetch

salt/utils/gitfs.py:2183–2257  ·  view source on GitHub ↗

Fetch the repo. If the local copy was updated, return True. If the local copy was already up-to-date, return False.

(self)

Source from the content-addressed store, hash-verified

2181 return self._get_envs_from_ref_paths(ref_paths)
2182
2183 def _fetch(self):
2184 """
2185 Fetch the repo. If the local copy was updated, return True. If the
2186 local copy was already up-to-date, return False.
2187 """
2188 origin = self.repo.remotes[0]
2189 refs_pre = self.repo.listall_references()
2190 fetch_kwargs = {"proxy": True}
2191
2192 # pygit2 radically changed fetching in 0.23.2
2193 if self.remotecallbacks is not None:
2194 fetch_kwargs["callbacks"] = self.remotecallbacks
2195 else:
2196 if self.credentials is not None:
2197 origin.credentials = self.credentials
2198 try:
2199 fetch_kwargs["prune"] = pygit2.GIT_FETCH_PRUNE
2200 except AttributeError:
2201 # pruning only available in pygit2 >= 0.26.2
2202 pass
2203 try:
2204 fetch_results = origin.fetch(**fetch_kwargs)
2205
2206 except GitError as exc: # pylint: disable=broad-except
2207 exc_str = get_error_message(exc).lower()
2208 if "unsupported url protocol" in exc_str and isinstance(
2209 self.credentials, pygit2.Keypair
2210 ):
2211 log.error(
2212 "Unable to fetch SSH-based %s remote '%s'. "
2213 "You may need to add ssh:// to the repo string or "
2214 "libgit2 must be compiled with libssh2 to support "
2215 "SSH authentication.",
2216 self.role,
2217 self.id,
2218 exc_info=True,
2219 )
2220 elif "authentication required but no callback set" in exc_str:
2221 log.error(
2222 "%s remote '%s' requires authentication, but no "
2223 "authentication configured",
2224 self.role,
2225 self.id,
2226 exc_info=True,
2227 )
2228 else:
2229 log.error(
2230 "Error occurred fetching %s remote '%s': %s",
2231 self.role,
2232 self.id,
2233 exc,
2234 exc_info=True,
2235 )
2236 return False
2237 try:
2238 # pygit2.Remote.fetch() returns a dict in pygit2 < 0.21.0
2239 received_objects = fetch_results["received_objects"]
2240 except (AttributeError, TypeError):

Callers

nothing calls this directly

Calls 5

clean_stale_refsMethod · 0.95
get_error_messageFunction · 0.90
debugMethod · 0.80
fetchMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected