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

Method checkout

salt/utils/gitfs.py:1829–2045  ·  view source on GitHub ↗

Checkout the configured branch/tag fetch_on_fail If checkout fails perform a fetch then try to checkout again.

(self, fetch_on_fail=True)

Source from the content-addressed store, hash-verified

1827 return obj.get_object()
1828
1829 def checkout(self, fetch_on_fail=True):
1830 """
1831 Checkout the configured branch/tag
1832
1833 fetch_on_fail
1834 If checkout fails perform a fetch then try to checkout again.
1835 """
1836 self.fetch_request_check()
1837 tgt_ref = self.get_checkout_target()
1838 local_ref = "refs/heads/" + tgt_ref
1839 remote_ref = "refs/remotes/origin/" + tgt_ref
1840 tag_ref = "refs/tags/" + tgt_ref
1841
1842 try:
1843 local_head = self.repo.lookup_reference("HEAD")
1844 except KeyError:
1845 log.warning("HEAD not present in %s remote '%s'", self.role, self.id)
1846 return None
1847
1848 try:
1849 head_sha = str(self.peel(local_head).id)
1850 except AttributeError:
1851 # Shouldn't happen, but just in case a future pygit2 API change
1852 # breaks things, avoid a traceback and log an error.
1853 log.error(
1854 "Unable to get SHA of HEAD for %s remote '%s'", self.role, self.id
1855 )
1856 return None
1857 except KeyError:
1858 head_sha = None
1859
1860 refs = self.repo.listall_references()
1861
1862 def _perform_checkout(checkout_ref, branch=True):
1863 """
1864 DRY function for checking out either a branch or a tag
1865 """
1866 try:
1867 with self.gen_lock(lock_type="checkout"):
1868 # Checkout the local branch corresponding to the
1869 # remote ref.
1870 self.repo.checkout(checkout_ref)
1871 if branch:
1872 self.repo.reset(pygit2_id, pygit2.GIT_RESET_HARD)
1873 return True
1874 except GitLockError as exc:
1875 if exc.errno == errno.EEXIST:
1876 # Re-raise with a different strerror containing a
1877 # more meaningful error message for the calling
1878 # function.
1879 raise GitLockError(
1880 exc.errno,
1881 f"Checkout lock exists for {self.role} remote '{self.id}'",
1882 )
1883 else:
1884 log.error(
1885 "Error %d encountered obtaining checkout lock "
1886 "for %s remote '%s'",

Callers 10

checkoutMethod · 0.45
_perform_checkoutMethod · 0.45
do_checkoutMethod · 0.45
test_checkout_pygit2Function · 0.45
test_checkoutFunction · 0.45
_test_winrepo_simpleFunction · 0.45
_test_envFunction · 0.45
_test_multiple_reposFunction · 0.45
_test_fetch_requestFunction · 0.45

Calls 9

peelMethod · 0.95
fetch_request_checkMethod · 0.80
get_checkout_targetMethod · 0.80
warningMethod · 0.80
check_rootMethod · 0.80
debugMethod · 0.80
errorMethod · 0.45
partitionMethod · 0.45
fetchMethod · 0.45

Tested by 7

test_checkout_pygit2Function · 0.36
test_checkoutFunction · 0.36
_test_winrepo_simpleFunction · 0.36
_test_envFunction · 0.36
_test_multiple_reposFunction · 0.36
_test_fetch_requestFunction · 0.36