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

Fix tests when run from git hooks #334

Closed
joshrabinowitz opened this issue Jan 29, 2019 · 4 comments
Closed

Fix tests when run from git hooks #334

joshrabinowitz opened this issue Jan 29, 2019 · 4 comments

Comments

@joshrabinowitz
Copy link
Collaborator

joshrabinowitz commented Jan 29, 2019

CONTRIBUTING.md says to use make install-hooks to install pre- and post-commit hooks, but if you do that then the self-tests fail on commit:

% # make a meaningless, whitespace change to a file in src/commands/
% git commit -a
1..88
ok 1 run 'add' normally
ok 2 run 'add' for unignored file

...

ok 27 run 'hide' with '-P'
not ok 28 run 'hide' from inside subdirectory
# (in test file /home/joshr/gitsrc/git-secret/tests/test_hide.bats, line 88)
#   `[ "$status" -eq 0 ]' failed
# rm: cannot remove ‘space file’: No such file or directory
# fatal: Not a git repository: '.git'
# find: ‘/tmp/tmp.aBlVDAbUQF’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-rtkit-daemon.service-KNfvrc’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-colord.service-ivZa8u’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-fwupd.service-07aFP3’: Permission denied
# find: ‘/tmp/tmp.UbZvBTtYAa’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-chronyd.service-G1ov1r’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-cups.service-kAx3OS’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-bolt.service-IZaN9N’: Permission denied
# find: ‘/tmp/tmp.1L9d7x7l3I’: Permission denied
not ok 29 run 'hide' with missing file
# (from function `set_state_secret_init' in file /home/joshr/gitsrc/git-secret/tests/_test_base.bash, line 202,
#  from function `setup' in test file /home/joshr/gitsrc/git-secret/tests/test_hide.bats, line 14)
#   `set_state_secret_init' failed
# find: ‘/tmp/tmp.aBlVDAbUQF’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-rtkit-daemon.service-KNfvrc’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-colord.service-ivZa8u’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-fwupd.service-07aFP3’: Permission denied
# find: ‘/tmp/tmp.UbZvBTtYAa’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-chronyd.service-G1ov1r’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-cups.service-kAx3OS’: Permission denied
# find: ‘/tmp/systemd-private-8b7dddc415874f87ad46f53ff94b4d7f-bolt.service-IZaN9N’: Permission denied
# find: ‘/tmp/tmp.1L9d7x7l3I’: Permission denied
ok 30 run 'hide' with multiple files

...
```
@sobolevn
Copy link
Owner

@joshrabinowitz that's why I had this solution:

# This test covers this issue:
# https://github.com/sobolevn/git-secret/issues/85 task 1
if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then
skip "this test is skipped while 'git commmit'"
fi

@joshrabinowitz
Copy link
Collaborator Author

@sobolevn but.... why does running under a 'git commit' fail?

Is there a better fix for this that doesn't require disabling the test in that situation?

@sobolevn
Copy link
Owner

sobolevn commented Feb 6, 2019

That's some deep git magic about its internal state: it is obviously different in normat mode and "commiting" state. I am not sure how different it is, however. And I was not able to find the correct solution back then.

@joshrabinowitz
Copy link
Collaborator Author

joshrabinowitz commented Feb 6, 2019

For clarity, the issue is related to git rev-parse not working as expected when run from this pre-commit githook:

calls to rev-parse are here:

result=$(git rev-parse --is-inside-work-tree > /dev/null 2>&1; echo $?)

and
result=$(git rev-parse --show-toplevel)

joshrabinowitz added a commit that referenced this issue Feb 10, 2019
* fix test under githooks, fix typos, mention #334 as relevant
joshrabinowitz added a commit that referenced this issue Feb 11, 2019
* fix test under git hook. Actually closes #334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants