Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to detect a source control manager in worktree outside of source repo #93

Closed
forivall opened this issue Oct 25, 2019 · 6 comments

Comments

@forivall
Copy link

Similar to #90.

git worktree allows one to use a single git repo with multiple working directories.

The .git in the worktree is a file that looks like this:

gitdir: /Users/emily/code/pubrepos/husky/.git/worktrees/husky-worktree

and the worktree can be in a different directory than inside the repo, so the findup solution doesn't work.

~pubrepos/husky forivall/workdir-and-multi-repo
» git worktree add ../husky-worktree
Preparing worktree (new branch 'husky-worktree')
HEAD is now at f3d8af1 add reproduction attempt for workdir issue #580

~pubrepos/husky forivall/workdir-and-multi-repo
» git st
## forivall/workdir-and-multi-repo...forivall/forivall/workdir-and-multi-repo

~pubrepos/husky forivall/workdir-and-multi-repo
» cd ../husky-worktree

~pubrepos/husky-worktree husky-worktree
» pretty-quick
/Users/emily/.config/yarn/global/node_modules/pretty-quick/dist/index.js:40
    throw new Error('Unable to detect a source control manager.');
    ^

Error: Unable to detect a source control manager.
    at _default (/Users/emily/.config/yarn/global/node_modules/pretty-quick/dist/index.js:40:11)
    at Object.<anonymous> (/Users/emily/.config/yarn/global/node_modules/pretty-quick/bin/pretty-quick.js:12:27)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
@forivall
Copy link
Author

forivall commented Oct 26, 2019

For now, I'm using the following patch (with patch-package):

diff --git a/node_modules/pretty-quick/dist/scms/git.js b/node_modules/pretty-quick/dist/scms/git.js
index 13ef4fd..5a1936b 100644
--- a/node_modules/pretty-quick/dist/scms/git.js
+++ b/node_modules/pretty-quick/dist/scms/git.js
@@ -10,6 +10,7 @@ var _findUp = _interopRequireDefault(require("find-up"));
 var _execa = _interopRequireDefault(require("execa"));
 
 var _path = require("path");
+var _fs = require("fs");
 
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
@@ -17,13 +18,19 @@ const name = 'git';
 exports.name = name;
 
 const detect = directory => {
-  const gitDirectory = _findUp.default.sync('.git', {
+  const gitDirectory = _findUp.default.sync((p) => {
+		try {
+			_fs.statSync(`${p}/.git`)
+			return '.';
+		} catch (err) {}
+		return undefined;
+	}, {
     cwd: directory,
     type: 'directory'
   });
 
   if (gitDirectory) {
-    return (0, _path.dirname)(gitDirectory);
+    return gitDirectory;
   }
 };

@viceice
Copy link

viceice commented Nov 14, 2019

I'm having the same problem since git 2.24.0.windows.2 and node v12.13.0.

> pretty-quick --staged

C:\Users\kriese\projects\vsaf\vsaf-maintanance\node_modules\pretty-quick\dist\index.js:40
    throw new Error('Unable to detect a source control manager.');

@viceice
Copy link

viceice commented Nov 14, 2019

Maybe pretty-quick should use the following commands to find toplevel and git path.

git rev-parse --show-toplevel
git rev-parse --git-dir

@viceice
Copy link

viceice commented Nov 14, 2019

This can be closed, as it is fixed in v2.0.1

@azz azz closed this as completed Nov 14, 2019
@aralroca
Copy link

aralroca commented Dec 7, 2020

Happening to me with 2.2.1 and Node 13.7.0

@jsenich-r7
Copy link

This is still an issue for me as of 3.1.0. It works for me if I use the patch from @forivall above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants