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

[Feature Request] Running git-exec-and-restage within a subdirectory #14

Open
JLHwung opened this issue Jun 30, 2017 · 2 comments
Open

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Jun 30, 2017

This issue is related to lint-staged/lint-staged#65, if git-exec-and-restage is installed within a subdirectory, it will report error like

Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

Error: Exited with status 129

A gitDir option is in need to support subdirectory, and we will use the resolved location to set cwd in each spawn

const gitDir = path.resolve(config.gitDir) || process.cwd();
await spawn(
      "git",
      [
        "diff-index",
        "--cached",
        "--name-only",
        "--diff-filter=ACDMRTUXB",
        revision,
        "--"
      ],
      {
        encoding: "utf8",
        cwd: gitDir
      }
    )

However we don't have a config system, so it depends on the owner to design the config. If there is not any preference, cosmiconfig will be a good fit.

Thank you.

@frenic
Copy link

frenic commented Sep 18, 2017

A workaround using lint-staged is to create a run-script that change to Git root directory before git-exec-and-restage:

// `.lintstagedrc` in subdir
{
  "gitDir": "../",
  "linters": {
    "*.{ts,tsx}": ["precommit-prettier"]
  }
}

// `package.json` in subdir
{
  // ...
  "scripts": {
    "precommit": "lint-staged",
    "precommit-prettier": "cd .. && git-exec-and-restage prettier --write --"
  }
}

Ugly but it works for me for now.

@motiz88
Copy link
Owner

motiz88 commented May 20, 2018

This should probably just work from anywhere inside a Git repo - I don't see a need for config really. Thoughts?

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

3 participants