({ cwd }: { cwd: string })
| 137 | } |
| 138 | |
| 139 | export async function isRepoShallow({ cwd }: { cwd: string }) { |
| 140 | const isShallowRepoOutput = ( |
| 141 | await spawn("git", ["rev-parse", "--is-shallow-repository"], { |
| 142 | cwd, |
| 143 | }) |
| 144 | ).stdout |
| 145 | .toString() |
| 146 | .trim(); |
| 147 | |
| 148 | if (isShallowRepoOutput === "--is-shallow-repository") { |
| 149 | // We have an old version of Git (<2.15) which doesn't support `rev-parse --is-shallow-repository` |
| 150 | // In that case, we'll test for the existence of .git/shallow. |
| 151 | |
| 152 | // Firstly, find the .git folder for the repo; note that this will be relative to the repo dir |
| 153 | const gitDir = ( |
| 154 | await spawn("git", ["rev-parse", "--git-dir"], { cwd }) |
| 155 | ).stdout |
| 156 | .toString() |
| 157 | .trim(); |
| 158 | |
| 159 | const fullGitDir = path.resolve(cwd, gitDir); |
| 160 | |
| 161 | // Check for the existence of <gitDir>/shallow |
| 162 | return fs.existsSync(path.join(fullGitDir, "shallow")); |
| 163 | } else { |
| 164 | // We have a newer Git which supports `rev-parse --is-shallow-repository`. We'll use |
| 165 | // the output of that instead of messing with .git/shallow in case that changes in the future. |
| 166 | return isShallowRepoOutput === "true"; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | export async function deepenCloneBy({ by, cwd }: { by: number; cwd: string }) { |
| 171 | await spawn("git", ["fetch", `--deepen=${by}`], { cwd }); |
no outgoing calls
no test coverage detected