git-repo-updater
git-repo-updater copied to clipboard
clean up deleted repo's?
Is there any way to have this automatically delete repositories that no longer exist?
Example of current:
git_checkout:
Fetching origin: error: Could not read from remote repository. Please ma
ke sure you have the correct access rights and the repository exists. Updating master: up to date.
There's nothing built-in to do this, and it seems a bit dangerous to add because a temporary issue with the remote (like a permissions issue) would cause your local copy to get deleted. You also need to consider situations with multiple remotes or when we have branches out of sync with the remote we can't update. Basically, I'm not sure what a "safe" check for this would look like.
Maybe I'm not using this application for it's intended purpose? At my work, we have around 500 repos. With that many, they get moved or deleted fairly often and the only way for me to fix it is to find them by hand and manually delete them.
Do you have any suggestions for how I can remove these deleted repos?
Something like this will work:
gitup . -e 'bash -c "git ls-remote --exit-code >/dev/null 2>&1 || (rm -rf $(git rev-parse --show-toplevel) && echo deleted)"'
Just keep in mind that it's inherently very dangerous if you are ever unable to access the remote for some reason.
At the very least you can check that the remote server answers on port 22 or 443 (depending on if you use ssh or https) by grepping the config in .git
and testing with nc
. Just to make sure it's not just the server being offline.
But if you want to try and get all the edge cases (ssh key not in the keychain/agent anymore, temporary access issue, etc. etc.) it's going to be real hard.
Also it doesn't sound fun working at a company that things having 500 git repos is a good idea :-D
You could have a process that "quarantine" these repos. Move them to a secondary folder you can recover them from. And then have a cron job that deletes them after x days based on mtime.
Ha. That's a creative approach. Thank you. I'm currently running gitup on a Windows machine so I'll install it on a unix machine and give this a shot. Thanks for taking the time to answer the question.
Something like this will work:
gitup . -e 'bash -c "git ls-remote --exit-code >/dev/null 2>&1 || (rm -rf $(git rev-parse --show-toplevel) && echo deleted)"'
Just keep in mind that it's inherently very dangerous if you are ever unable to access the remote for some reason.
gitup -n will clean up it's bookmarks file for repo's that are no longer there.