prefix_length = prefix ? strlen(prefix) : 0;
if (vpath && prefix)
- vpath = prefix_filename(prefix, prefix_length, vpath);
+ vpath = xstrdup(prefix_filename(prefix, prefix_length, vpath));
git_config(git_default_config, NULL);
for (i = 0 ; i < argc; i++) {
const char *arg = argv[i];
+ char *to_free = NULL;
if (0 <= prefix_length)
- arg = prefix_filename(prefix, prefix_length, arg);
+ arg = to_free =
+ xstrdup(prefix_filename(prefix, prefix_length, arg));
hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg,
flags, literally);
+ free(to_free);
}
if (stdin_paths)
)
'
+test_expect_success '--path works in a subdirectory' '
+ (
+ cd subdir &&
+ path1_sha=$(git hash-object --path=../file1 ../file0) &&
+ path0_sha=$(git hash-object --path=../file0 ../file1) &&
+ test "$file0_sha" = "$path0_sha" &&
+ test "$file1_sha" = "$path1_sha"
+ )
+'
+
test_expect_success 'check that --no-filters option works' '
nofilters_file1=$(git hash-object --no-filters file1) &&
test "$file0_sha" = "$nofilters_file1" &&