Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"prettier": "^3.0.0"
},
"dependencies": {
"find-up": "^5.0.0",
"empathic": "^1.1.0",
"ignore": "^7.0.3",
"mri": "^1.2.0",
"picocolors": "^1.1.1",
Expand Down
41 changes: 4 additions & 37 deletions src/scms/git.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import fs from 'fs'
import path from 'path'

import findUp from 'find-up'
import { Output, exec } from 'tinyexec'
import * as find from 'empathic/find'
import { exec, Output } from 'tinyexec'

export const name = 'git'

export const detect = (directory: string) => {
if (fs.existsSync(path.join(directory, '.git'))) {
return directory
}

const gitDirectory = findUp.sync('.git', {
cwd: directory,
type: 'directory',
})

const gitWorkTreeFile = findUp.sync('.git', {
cwd: directory,
type: 'file',
})

// if both of these are null then return null
if (!gitDirectory && !gitWorkTreeFile) {
return null
}

// if only one of these exists then return it
if (gitDirectory && !gitWorkTreeFile) {
return path.dirname(gitDirectory)
}

if (gitWorkTreeFile && !gitDirectory) {
return path.dirname(gitWorkTreeFile)
}

const gitRepoDirectory = path.dirname(gitDirectory!)
const gitWorkTreeDirectory = path.dirname(gitWorkTreeFile!)
// return the deeper of these two
return gitRepoDirectory.length > gitWorkTreeDirectory.length
? gitRepoDirectory
: gitWorkTreeDirectory
const found = find.up('.git', { cwd: directory })
return found ? path.dirname(found) : null
}

const runGit = (directory: string, args: string[]) =>
Expand Down
13 changes: 4 additions & 9 deletions src/scms/hg.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import path from 'path'

import findUp from 'find-up'
import { Output, exec } from 'tinyexec'
import * as find from 'empathic/find'
import { exec, Output } from 'tinyexec'

export const name = 'hg'

export const detect = (directory: string) => {
const hgDirectory = findUp.sync('.hg', {
cwd: directory,
type: 'directory',
})
if (hgDirectory) {
return path.dirname(hgDirectory)
}
const found = find.up('.hg', { cwd: directory })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is a .hg file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always a directory. If you have a .hg file your mercurial project would be broken

Copy link
Member

@JounQin JounQin Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that just means there is a .hg file and it's not a mercurial project.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can stat the result to check if it's a directory, tho the odds of this happening is very low.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how previous codes work. Dependency migration should not change any current behavior.

if (found) return path.dirname(found)
}

const runHg = (directory: string, args: string[]) =>
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6625,6 +6625,13 @@ __metadata:
languageName: node
linkType: hard

"empathic@npm:^1.1.0":
version: 1.1.0
resolution: "empathic@npm:1.1.0"
checksum: 1e41763802f14e5fa2522063f8f93e161c64916698f39e493a3e274356e39aa6f60d60f33063c92f9d5c5426fd33d9cb33baed2885a194648254181ce5495a9c
languageName: node
linkType: hard

"encoding@npm:^0.1.13":
version: 0.1.13
resolution: "encoding@npm:0.1.13"
Expand Down Expand Up @@ -12934,8 +12941,8 @@ __metadata:
"@types/picomatch": ^3.0.2
"@unts/patch-package": ^8.1.1
clean-pkg-json: ^1.2.0
empathic: ^1.1.0
eslint: ^8.57.1
find-up: ^5.0.0
ignore: ^7.0.3
jest: ^29.7.0
lint-staged: ^15.4.3
Expand Down
Loading