| 101 | |
| 102 | |
| 103 | def clone_cppcheck(repo_path, migrate_from_path): |
| 104 | repo_git_dir = os.path.join(repo_path, '.git') |
| 105 | if os.path.exists(repo_git_dir): |
| 106 | return |
| 107 | # Attempt to migrate clone directory used prior to 1.3.17 |
| 108 | if os.path.exists(migrate_from_path): |
| 109 | os.rename(migrate_from_path, repo_path) |
| 110 | else: |
| 111 | # A shallow git clone (depth = 1) is enough for building and scanning. |
| 112 | # Do not checkout until fetch_cppcheck_version. |
| 113 | subprocess.check_call(['git', 'clone', '--depth=1', '--no-checkout', CPPCHECK_REPO_URL, repo_path]) |
| 114 | # Checkout an empty branch to allow "git worktree add" for main later on |
| 115 | try: |
| 116 | # git >= 2.27 |
| 117 | subprocess.check_call(['git', 'switch', '--orphan', 'empty'], cwd=repo_path) |
| 118 | except subprocess.CalledProcessError: |
| 119 | subprocess.check_call(['git', 'checkout', '--orphan', 'empty'], cwd=repo_path) |
| 120 | |
| 121 | |
| 122 | def checkout_cppcheck_version(repo_path, version, cppcheck_path): |