When only GitPython is installed, and no gitfs_provider is set, an error
about pygit2 not being available is logged. This should not happen, as
gitfs should just select the first available out of pygit2, gitpython,
and dulwich.
This fixes#17945 by suppressing the error.
Also rewrite salt.fileserver.gitfs.clear_lock() to accept a repo conf
dict instead of a pattern, so that locking and unlocking in
salt.fileserver.gitfs.update() can use the same code as the fileserver
runner.
Also rewrite salt.fileserver.svnfs.clear_lock() to accept a repo conf
dict instead of a pattern, so that locking and unlocking in
salt.fileserver.svnfs.update() can use the same code as the fileserver
runner.
Also rewrite salt.fileserver.hgfs.clear_lock() to accept a repo conf
dict instead of a pattern, so that locking and unlocking in
salt.fileserver.hgfs.update() can use the same code as the fileserver
runner.
Rather than using a subtractive approach (doing an os.listdir() and then
removing the stuff we don't want to delete), instead use an additive
approach and assemble a list of things we *do* want to delete. This
makes the function easier to read and maintain.
This loop is designed to remove the cache directories from old remotes.
shutil.rmtree() will throw an OSError, however, if run on something
other than a directory. This commit catches this exception and logs it.
Seeing this error in the log will be a reminder that some new file has
been added to the cachedir to be used by the FS backend, and that it
needs to be added to the exclusion logic above.
Older versions of hglib did not raise an exception when no refs were
found. This commit catches the exception, fixing a traceback that
prevents new remotes from ever being fetched for the first time.
This fixes the same branch/tag detection issues resolved for GitPython
in the previous commit. Additionally, it refines the work done to fix
this issue in GitPython.
The existing method of change detection only caught changes to existing
branches. New branches and deleted branches weren't detected as changes.
It turns out that the return value of a fetch with no changes is an
empty list, so simply checking if the return value is non-empty catches
instances where there is a new branch, as well as instances where an
existing branch was updated.
Additionally, the existence of stale refs after a fetch is now used to
determine if a local branch no longer exists on the remote repository.
These stale refs are now deleted to keep the local checkout clean.