forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 106
Index changed hook #64
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
Merged
kewillford
merged 4 commits into
microsoft:gvfs-2.19.1
from
kewillford:index-changed-hook
Nov 29, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
61d531a
read-cache: add post-indexchanged hook
benpeart 80eabc5
read-cache: post-indexchanged hook add skip-worktree bit changing sup…
benpeart ce4e661
read-cache: add test for post-indexchanged hook
benpeart 12b8b62
Add documentation for the post-indexchanged hook
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #!/bin/sh | ||
|
|
||
| test_description='post index changed hook' | ||
|
|
||
| . ./test-lib.sh | ||
|
|
||
| test_expect_success 'setup' ' | ||
| mkdir -p dir1 && | ||
| touch dir1/file1.txt && | ||
| echo testing >dir1/file2.txt && | ||
| git add . && | ||
| git commit -m "initial" | ||
| ' | ||
|
|
||
| test_expect_success 'test status, add, commit, others trigger hook without flags set' ' | ||
| mkdir -p .git/hooks && | ||
| write_script .git/hooks/post-indexchanged <<-\EOF && | ||
| if test "$1" -eq 1; then | ||
| echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure | ||
| exit 1 | ||
| fi | ||
| if test "$2" -eq 1; then | ||
| echo "Invalid combination of flags passed to hook; updated_skipworktree is set." >testfailure | ||
| exit 1 | ||
| fi | ||
| if test -f ".git/index.lock"; then | ||
| echo ".git/index.lock exists" >testfailure | ||
| exit 3 | ||
| fi | ||
| if ! test -f ".git/index"; then | ||
| echo ".git/index does not exist" >testfailure | ||
| exit 3 | ||
| fi | ||
| echo "success" >testsuccess | ||
| EOF | ||
| mkdir -p dir2 && | ||
| touch dir2/file1.txt && | ||
| touch dir2/file2.txt && | ||
| git status && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git add . && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git commit -m "second" && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git checkout -- dir1/file1.txt && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git update-index && | ||
| test_path_is_missing testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git reset --soft && | ||
| test_path_is_missing testsuccess && | ||
| test_path_is_missing testfailure | ||
| ' | ||
|
|
||
| test_expect_success 'test checkout and reset trigger the hook' ' | ||
| write_script .git/hooks/post-indexchanged <<-\EOF && | ||
| if test "$1" -eq 1 && test "$2" -eq 1; then | ||
| echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure | ||
| exit 1 | ||
| fi | ||
| if test "$1" -eq 0 && test "$2" -eq 0; then | ||
| echo "Invalid combination of flags passed to hook; neither updated_workdir or updated_skipworktree are set." >testfailure | ||
| exit 2 | ||
| fi | ||
| if test "$1" -eq 1; then | ||
| if test -f ".git/index.lock"; then | ||
| echo "updated_workdir set but .git/index.lock exists" >testfailure | ||
| exit 3 | ||
| fi | ||
| if ! test -f ".git/index"; then | ||
| echo "updated_workdir set but .git/index does not exist" >testfailure | ||
| exit 3 | ||
| fi | ||
| else | ||
| echo "update_workdir should be set for checkout" >testfailure | ||
| exit 4 | ||
| fi | ||
| echo "success" >testsuccess | ||
| EOF | ||
| git checkout master && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git checkout HEAD && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git reset --hard && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git checkout -b test && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure | ||
| ' | ||
|
|
||
| test_expect_success 'test reset --mixed and update-index triggers the hook' ' | ||
| write_script .git/hooks/post-indexchanged <<-\EOF && | ||
| if test "$1" -eq 1 && test "$2" -eq 1; then | ||
| echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure | ||
| exit 1 | ||
| fi | ||
| if test "$1" -eq 0 && test "$2" -eq 0; then | ||
| echo "Invalid combination of flags passed to hook; neither updated_workdir or updated_skipworktree are set." >testfailure | ||
| exit 2 | ||
| fi | ||
| if test "$2" -eq 1; then | ||
| if test -f ".git/index.lock"; then | ||
| echo "updated_skipworktree set but .git/index.lock exists" >testfailure | ||
| exit 3 | ||
| fi | ||
| if ! test -f ".git/index"; then | ||
| echo "updated_skipworktree set but .git/index does not exist" >testfailure | ||
| exit 3 | ||
| fi | ||
| else | ||
| echo "updated_skipworktree should be set for reset --mixed and update-index" >testfailure | ||
| exit 4 | ||
| fi | ||
| echo "success" >testsuccess | ||
| EOF | ||
| git reset --mixed HEAD~1 && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git hash-object -w --stdin <dir1/file2.txt >expect && | ||
| git update-index --cacheinfo 100644 "$(cat expect)" dir1/file1.txt && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure && | ||
| git update-index --skip-worktree dir1/file2.txt && | ||
| git update-index --remove dir1/file2.txt && | ||
| test_path_is_file testsuccess && rm -f testsuccess && | ||
| test_path_is_missing testfailure | ||
| ' | ||
|
|
||
| test_done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.