Download next.js/packages/create-next-app/helpers/git.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/create-next-app/helpers/git.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/create-next-app/helpers/git.ts
-
curl -L -o git.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/create-next-app/helpers/git.ts
1.38 kB
| /* eslint-disable import/no-extraneous-dependencies */ | |
| import { execSync } from 'node:child_process' | |
| import { join } from 'node:path' | |
| import { rmSync } from 'node:fs' | |
| function isInGitRepository(): boolean { | |
| try { | |
| execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }) | |
| return true | |
| } catch (_) {} | |
| return false | |
| } | |
| function isInMercurialRepository(): boolean { | |
| try { | |
| execSync('hg --cwd . root', { stdio: 'ignore' }) | |
| return true | |
| } catch (_) {} | |
| return false | |
| } | |
| function isDefaultBranchSet(): boolean { | |
| try { | |
| execSync('git config init.defaultBranch', { stdio: 'ignore' }) | |
| return true | |
| } catch (_) {} | |
| return false | |
| } | |
| export function tryGitInit(root: string): boolean { | |
| let didInit = false | |
| try { | |
| execSync('git --version', { stdio: 'ignore' }) | |
| if (isInGitRepository() || isInMercurialRepository()) { | |
| return false | |
| } | |
| execSync('git init', { stdio: 'ignore' }) | |
| didInit = true | |
| if (!isDefaultBranchSet()) { | |
| execSync('git checkout -b main', { stdio: 'ignore' }) | |
| } | |
| execSync('git add -A', { stdio: 'ignore' }) | |
| execSync('git commit -m "Initial commit from Create Next App"', { | |
| stdio: 'ignore', | |
| }) | |
| return true | |
| } catch (e) { | |
| if (didInit) { | |
| try { | |
| rmSync(join(root, '.git'), { recursive: true, force: true }) | |
| } catch (_) {} | |
| } | |
| return false | |
| } | |
| } | |