git 判断路径是否是 git 仓库
git 判断路径是否是 git 仓库
import subprocess repo_dir = "../path/to/check/" command = ['git', 'rev-parse', '--is-inside-work-tree'] process = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=repo_dir, universal_newlines=True) process_output = process.communicate()[0] is_git_repo = str(process_output.strip()) if is_git_repo == "true": print("success! git repo found under {0}".format(repo_dir)) else: print("sorry. no git repo found under {0}".format(repo_dir))
参考链接:https://stackoverflow.com/questions/2044574/determine-if-directory-is-under-git-control
未经博主允许,禁止直接转载本博客任何内容(可以在文章中添加链接,禁止原文照搬),如需直接原文转载对应文章,请在该文章中留言联系博主,谢谢!!