@@ -123,6 +123,13 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
else
prefix = setup_git_directory_gently(&nongit);
+ /*
+ * TODO: Allow the hash algorithm to be configured by the user via a
+ * command line option when not using `-w`.
+ */
+ if (nongit)
+ repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
if (vpath && prefix) {
vpath_free = prefix_filename(prefix, vpath);
vpath = vpath_free;
@@ -260,4 +260,10 @@ test_expect_success '--literally with extra-long type' '
echo example | git hash-object -t $t --literally --stdin
'
+test_expect_success '--stdin outside of repository' '
+ nongit git hash-object --stdin <hello >actual &&
+ echo "$(test_oid hello)" >expect &&
+ test_cmp expect actual
+'
+
test_done
@@ -30,7 +30,7 @@ test_expect_success 'compute a patch-id outside repository' '
test_cmp patch-id.expect patch-id.actual
'
-test_expect_failure 'hash-object outside repository' '
+test_expect_success 'hash-object outside repository' '
git hash-object --stdin <sample.patch >hash.expect &&
(
cd non-repo &&