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

${staged} variable contains some temporary files #39

Closed
ultrr opened this issue Mar 9, 2022 · 3 comments
Closed

${staged} variable contains some temporary files #39

ultrr opened this issue Mar 9, 2022 · 3 comments
Labels
bug Something isn't working fixed

Comments

@ultrr
Copy link

ultrr commented Mar 9, 2022

Version

0.4.0

Details

I was running a git hook with several steps configured. I was expecting only REAL staged files to be committed but unfortunately there were some additional staged files which shouldn't be added to ${staged} variable.

Steps to reproduce

  1. dotnet new tool-manifest
  2. dotnet tool install JetBrains.ReSharper.GlobalTools
  3. dotnet tool install ReGitLint
  4. dotnet tool install Husky
  5. configure Husky, using following task-runner.json
{
  "tasks": [
    {
      "name": "before - echo staged from husky",
      "command": "echo",
      "args": ["${staged}"]
    },
    {
      "name": "reglint",
      "command": "dotnet",
      "args": ["regitlint", "-f", "staged", "--jb", "--verbosity=WARN"]
    },
    {
      "name": "after - echo staged from husky",
      "command": "echo",
      "args": ["${staged}"]
    },
    {
      "name": "after - echo staged from git",
      "command": "git",
      "args": ["diff", "--name-only", "--cached"]
    },
    {
      "name": "after - echo staged from ???",
      "command": "git",
      "args": ["diff-index", "--cached", "--diff-filter=AM", "--no-renames", "--name-only", "HEAD"]
    }
  ]
}
  1. as you can see in git log output, echo of ${staged} variable includes other (temporary?) files, while those files aren't included while running git diff/diff-index commands manually. In our use case, we want to run git add ${staged} after regitlint but it results in committing those temporary files as well.
@ultrr ultrr added the bug Something isn't working label Mar 9, 2022
@alirezanet
Copy link
Owner

alirezanet commented Mar 9, 2022

I don't totally understand what is the problem!? Since husky doesn't change the file states.
how do you add your files to git in the first place (staging step)? Your reproducible example doesn't do anything because nothing is staged yet.
image

also, I've tried git add test.txt to stage a file:
02

everything was normal except weird behavior from reglint tool (I have no idea why it is scanning my entire system and found a different project !)

If you think this is a husky-related bug, please remove other third-party tools and give me a reproducible example.

thanks

@alirezanet alirezanet added need more information Need more information and removed bug Something isn't working labels Mar 9, 2022
@ultrr
Copy link
Author

ultrr commented Mar 9, 2022

My bad! Forgot to include the output.
Managed to recreate the issue on a fresh solution, with usage of Husky.Net only.

Link to the repo with said solution: https:/ultrr/husky.net-staged-bug

Steps to reproduce:

  1. Clone the repo
  2. Restore the solution: dotnet restore
  3. Change the content of file1.txt: echo someContent123 >> file1.txt
  4. Change the content of file2.txt. Has to be different from file1.txt: echo someOtherContent123 >> file2.txt
  5. Stage both files: git add file1.txt file2.txt
  6. Commit the changes: git commit -m "test"

Output:

[Husky] 🚀 Loading tasks ...
--------------------------------------------------
[Husky] ⚡ Preparing task 'before-echo-staged'
[Husky] ⌛ Executing task 'before-echo-staged' ...
file1.txt file2.txt
[Husky]  ✔ Successfully executed in 2ms
--------------------------------------------------
[Husky] ⚡ Preparing task 'cp'
[Husky] ⌛ Executing task 'cp' ...
[Husky]  ✔ Successfully executed in 9ms
--------------------------------------------------
[Husky] ⚡ Preparing task 'after-echo-staged'
[Husky] ⌛ Executing task 'after-echo-staged' ...
file1.txt 26c27_file2.txt file2.txt
[Husky]  ✔ Successfully executed in 1ms
--------------------------------------------------
[Husky] ⚡ Preparing task 'git'
[Husky] ⌛ Executing task 'git' ...
[Husky]  ✔ Successfully executed in 8ms
--------------------------------------------------
[master 059d397] test
 3 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 63c0e_file2.txt

git status output:

On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    63c0e_file2.txt

no changes added to commit (use "git add" and/or "git commit -a")

@alirezanet alirezanet added bug Something isn't working and removed need more information Need more information labels Mar 9, 2022
@alirezanet
Copy link
Owner

Hi, Thank you for the repo
because in this case, you want to control git indexing situation to prevent husky interference I've added a new option -p to the run command that you can use in v0.4.2:

image

So you just need to update your run command to:

dotnet husky run -p

image

alirezanet added a commit that referenced this issue Jul 30, 2022
* feat: compile scripts

* fix: unit tests

* fix: your current branch does not have any commits yet #27 (#34)

* fix: your current branch does not have any commits yet #27

* fix: your current branch does not have any commits yet #27

* fix: staging files

* build: bump to v0.4.1

* fix(staged): add no-partial option to support normal staging process #39

* build: bump to v0.4.2

* fix: wrong cache folder path

* test: fix failed tests

* fix: update clean command cache folder path

* fix: tests failing on linux

Co-authored-by: AliReZa Sabouri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants