Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Even though "git hash-objects", which is a tool to take an on-filesystem data stream and put it into the Git object store, allowed to perform the "outside-world-to-Git" conversions (e.g. end-of-line conversions and application of the clean-filter), and it had the feature on by default from very early days, its reverse operation "git cat-file", which takes an object from the Git object store and externalize for the consumption by the outside world, lacked an equivalent mechanism to run the "Git-to-outside-world" conversion. The command learned the "--filters" option to do so. * js/cat-file-filters: cat-file: support --textconv/--filters in batch mode cat-file --textconv/--filters: allow specifying the path separately cat-file: introduce the --filters option cat-file: fix a grammo in the man page
- Loading branch information
Showing
3 changed files
with
190 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,64 @@ | ||
#!/bin/sh | ||
|
||
test_description='git cat-file filters support' | ||
. ./test-lib.sh | ||
|
||
test_expect_success 'setup ' ' | ||
echo "*.txt eol=crlf diff=txt" >.gitattributes && | ||
echo "hello" | append_cr >world.txt && | ||
git add .gitattributes world.txt && | ||
test_tick && | ||
git commit -m "Initial commit" | ||
' | ||
|
||
has_cr () { | ||
tr '\015' Q <"$1" | grep Q >/dev/null | ||
} | ||
|
||
test_expect_success 'no filters with `git show`' ' | ||
git show HEAD:world.txt >actual && | ||
! has_cr actual | ||
' | ||
|
||
test_expect_success 'no filters with cat-file' ' | ||
git cat-file blob HEAD:world.txt >actual && | ||
! has_cr actual | ||
' | ||
|
||
test_expect_success 'cat-file --filters converts to worktree version' ' | ||
git cat-file --filters HEAD:world.txt >actual && | ||
has_cr actual | ||
' | ||
|
||
test_expect_success 'cat-file --filters --path=<path> works' ' | ||
sha1=$(git rev-parse -q --verify HEAD:world.txt) && | ||
git cat-file --filters --path=world.txt $sha1 >actual && | ||
has_cr actual | ||
' | ||
|
||
test_expect_success 'cat-file --textconv --path=<path> works' ' | ||
sha1=$(git rev-parse -q --verify HEAD:world.txt) && | ||
test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" && | ||
git cat-file --textconv --path=hello.txt $sha1 >rot13 && | ||
test uryyb = "$(cat rot13 | remove_cr)" | ||
' | ||
|
||
test_expect_success '--path=<path> complains without --textconv/--filters' ' | ||
sha1=$(git rev-parse -q --verify HEAD:world.txt) && | ||
test_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err && | ||
test ! -s actual && | ||
grep "path.*needs.*filters" err | ||
' | ||
|
||
test_expect_success 'cat-file --textconv --batch works' ' | ||
sha1=$(git rev-parse -q --verify HEAD:world.txt) && | ||
test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" && | ||
printf "%s hello.txt\n%s hello\n" $sha1 $sha1 | | ||
git cat-file --textconv --batch >actual && | ||
printf "%s blob 6\nuryyb\r\n\n%s blob 6\nhello\n\n" \ | ||
$sha1 $sha1 >expect && | ||
test_cmp expect actual | ||
' | ||
|
||
test_done |