MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / isCurrentDirectoryBareGitRepo

Function isCurrentDirectoryBareGitRepo

source code/utils/git.ts:878–927  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

876 */
877/* eslint-disable custom-rules/no-sync-fs -- sync permission-eval check */
878export function isCurrentDirectoryBareGitRepo(): boolean {
879 const fs = getFsImplementation()
880 const cwd = getCwd()
881
882 const gitPath = join(cwd, '.git')
883 try {
884 const stats = fs.statSync(gitPath)
885 if (stats.isFile()) {
886 // worktree/submodule — Git follows the gitdir reference
887 return false
888 }
889 if (stats.isDirectory()) {
890 const gitHeadPath = join(gitPath, 'HEAD')
891 try {
892 // SECURITY: check isFile(). An attacker creating .git/HEAD as a
893 // DIRECTORY would pass a bare statSync but Git's setup_git_directory
894 // rejects it (not a valid HEAD) and falls back to cwd discovery.
895 if (fs.statSync(gitHeadPath).isFile()) {
896 // normal repo — .git/HEAD valid, Git won't fall back to cwd
897 return false
898 }
899 // .git/HEAD exists but is not a regular file — fall through
900 } catch {
901 // .git exists but no HEAD — fall through to bare-repo check
902 }
903 }
904 } catch {
905 // no .git — fall through to bare-repo indicator check
906 }
907
908 // No valid .git/HEAD found. Check if cwd has bare git repo indicators.
909 // Be cautious — flag if ANY of these exist without a valid .git reference.
910 // Per-indicator try/catch so an error on one doesn't mask another.
911 try {
912 if (fs.statSync(join(cwd, 'HEAD')).isFile()) return true
913 } catch {
914 // no HEAD
915 }
916 try {
917 if (fs.statSync(join(cwd, 'objects')).isDirectory()) return true
918 } catch {
919 // no objects/
920 }
921 try {
922 if (fs.statSync(join(cwd, 'refs')).isDirectory()) return true
923 } catch {
924 // no refs/
925 }
926 return false
927}
928/* eslint-enable custom-rules/no-sync-fs */

Callers 2

checkReadOnlyConstraintsFunction · 0.85

Calls 2

getFsImplementationFunction · 0.85
getCwdFunction · 0.85

Tested by

no test coverage detected