mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
refactor(git.ts): use git rev-parse to get the root directory of the repository (#46)
The function getStagedFiles has been refactored to use git rev-parse to get the root directory of the repository. This improves the reliability of the function as it will work regardless of the current working directory. The root directory is then passed to the git diff command to get the list of staged files. With only the --relative flag, staged diff(s) on files in a different same level directory as the current working one would not be found by the command.
This commit is contained in:
@@ -26,11 +26,17 @@ export const getOpenCommitIgnore = (): Ignore => {
|
||||
};
|
||||
|
||||
export const getStagedFiles = async (): Promise<string[]> => {
|
||||
const { stdout: files } = await execa('git', [
|
||||
'diff',
|
||||
'--name-only',
|
||||
'--cached',
|
||||
'--relative'
|
||||
const { stdout: gitDir } = await execa("git", [
|
||||
"rev-parse",
|
||||
"--show-toplevel"
|
||||
]);
|
||||
|
||||
const { stdout: files } = await execa("git", [
|
||||
"diff",
|
||||
"--name-only",
|
||||
"--cached",
|
||||
"--relative",
|
||||
gitDir
|
||||
]);
|
||||
|
||||
if (!files) return [];
|
||||
|
||||
Reference in New Issue
Block a user