From 9685dfb55a6f2578f6d6b1920f19642008aaf97a Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Tue, 24 Dec 2024 17:39:54 +0100 Subject: [PATCH] Fix git integration bug --- src/bin/tools/isKnownByGit.ts | 22 +++++++++++++++++++--- src/bin/tools/npmInstall.ts | 2 +- src/bin/tools/untrackFromGit.ts | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/bin/tools/isKnownByGit.ts b/src/bin/tools/isKnownByGit.ts index dbb12012..1acf7e1b 100644 --- a/src/bin/tools/isKnownByGit.ts +++ b/src/bin/tools/isKnownByGit.ts @@ -1,15 +1,31 @@ import * as child_process from "child_process"; -import { dirname as pathDirname, basename as pathBasename } from "path"; +import { + dirname as pathDirname, + basename as pathBasename, + join as pathJoin, + sep as pathSep +} from "path"; import { Deferred } from "evt/tools/Deferred"; +import * as fs from "fs"; export function getIsKnownByGit(params: { filePath: string }): Promise { const { filePath } = params; const dIsKnownByGit = new Deferred(); + let relativePath = pathBasename(filePath); + + let dirPath = pathDirname(filePath); + + while (!fs.existsSync(dirPath)) { + relativePath = pathJoin(pathBasename(dirPath), relativePath); + + dirPath = pathDirname(dirPath); + } + child_process.exec( - `git ls-files --error-unmatch ${pathBasename(filePath)}`, - { cwd: pathDirname(filePath) }, + `git ls-files --error-unmatch '${relativePath.split(pathSep).join("/")}'`, + { cwd: dirPath }, error => { if (error === null) { dIsKnownByGit.resolve(true); diff --git a/src/bin/tools/npmInstall.ts b/src/bin/tools/npmInstall.ts index 7a85d6d1..53a8d714 100644 --- a/src/bin/tools/npmInstall.ts +++ b/src/bin/tools/npmInstall.ts @@ -108,7 +108,7 @@ async function runPackageManagerInstall(params: { child.stdout.on("data", data => process.stdout.write(data)); child.stderr.on("data", data => { - if (data.toString("utf8").includes("has unmet peer dependency")) { + if (data.toString("utf8").includes("peer dependency")) { return; } diff --git a/src/bin/tools/untrackFromGit.ts b/src/bin/tools/untrackFromGit.ts index 3c602764..08f9dc0f 100644 --- a/src/bin/tools/untrackFromGit.ts +++ b/src/bin/tools/untrackFromGit.ts @@ -1,15 +1,31 @@ import * as child_process from "child_process"; -import { dirname as pathDirname, basename as pathBasename } from "path"; +import { + dirname as pathDirname, + basename as pathBasename, + join as pathJoin, + sep as pathSep +} from "path"; import { Deferred } from "evt/tools/Deferred"; +import { existsAsync } from "./fs.existsAsync"; export async function untrackFromGit(params: { filePath: string }): Promise { const { filePath } = params; const dDone = new Deferred(); + let relativePath = pathBasename(filePath); + + let dirPath = pathDirname(filePath); + + while (!(await existsAsync(dirPath))) { + relativePath = pathJoin(pathBasename(dirPath), relativePath); + + dirPath = pathDirname(dirPath); + } + child_process.exec( - `git rm --cached ${pathBasename(filePath)}`, - { cwd: pathDirname(filePath) }, + `git rm --cached '${relativePath.split(pathSep).join("/")}'`, + { cwd: dirPath }, error => { if (error !== null) { dDone.reject(error);