summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2016-09-12 20:23:17 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-09-13 15:45:45 -0700
commit0e94ee9415e6cf6952b755347b57319e93356210 (patch)
tree3a49f2fc07560773934d90bf28277200fb1bc380 /t
parentGit 2.8.4 (diff)
downloadtgif-0e94ee9415e6cf6952b755347b57319e93356210.tar.xz
hash-object: always try to set up the git repository
When "hash-object" is run without "-w", we don't need to be in a git repository at all; we can just hash the object and write its sha1 to stdout. However, if we _are_ in a git repository, we would want to know that so we can follow the normal rules for respecting config, .gitattributes, etc. This happens to work at the top-level of a git repository because we blindly read ".git/config", but as the included test shows, it does not work when you are in a subdirectory. The solution is to just do a "gentle" setup in this case. We already take care to use prefix_filename() on any filename arguments we get (to handle the "-w" case), so we don't need to do anything extra to handle the side effects of repo setup. An alternative would be to specify RUN_SETUP_GENTLY for this command in git.c, and then die if "-w" is set but we are not in a repository. However, the error messages generated at the time of setup_git_directory() are more detailed, so it's better to find out which mode we are in, and then call the appropriate function. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t1007-hash-object.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
index 7d2baa15bb..285871c24d 100755
--- a/t/t1007-hash-object.sh
+++ b/t/t1007-hash-object.sh
@@ -121,6 +121,17 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
git config --unset core.autocrlf
'
+test_expect_success 'gitattributes also work in a subdirectory' '
+ mkdir subdir &&
+ (
+ cd subdir &&
+ subdir_sha0=$(git hash-object ../file0) &&
+ subdir_sha1=$(git hash-object ../file1) &&
+ test "$file0_sha" = "$subdir_sha0" &&
+ test "$file1_sha" = "$subdir_sha1"
+ )
+'
+
test_expect_success 'check that --no-filters option works' '
echo fooQ | tr Q "\\015" >file0 &&
cp file0 file1 &&