Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/cat-file.c16
-rw-r--r--cache.h1
-rw-r--r--object-name.c3
-rwxr-xr-xt/t8007-cat-file-textconv.sh8
4 files changed, 14 insertions, 14 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index b5b130d79c..ad9b3eef4f 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -73,14 +73,17 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
struct object_info oi = OBJECT_INFO_INIT;
struct strbuf sb = STRBUF_INIT;
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
+ unsigned get_oid_flags = GET_OID_RECORD_PATH | GET_OID_ONLY_TO_DIE;
const char *path = force_path;
+ const int opt_cw = (opt == 'c' || opt == 'w');
+ if (!path && opt_cw)
+ get_oid_flags |= GET_OID_REQUIRE_PATH;
if (unknown_type)
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
- if (get_oid_with_context(the_repository, obj_name,
- GET_OID_RECORD_PATH,
- &oid, &obj_context))
+ if (get_oid_with_context(the_repository, obj_name, get_oid_flags, &oid,
+ &obj_context))
die("Not a valid object name %s", obj_name);
if (!path)
@@ -112,9 +115,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
return !has_object_file(&oid);
case 'w':
- if (!path)
- die("git cat-file --filters %s: <object> must be "
- "<sha1:path>", obj_name);
if (filter_object(path, obj_context.mode,
&oid, &buf, &size))
@@ -122,10 +122,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
break;
case 'c':
- if (!path)
- die("git cat-file --textconv %s: <object> must be <sha1:path>",
- obj_name);
-
if (textconv_object(the_repository, path, obj_context.mode,
&oid, 1, &buf, &size))
break;
diff --git a/cache.h b/cache.h
index eba12487b9..788127a986 100644
--- a/cache.h
+++ b/cache.h
@@ -1366,6 +1366,7 @@ struct object_context {
#define GET_OID_FOLLOW_SYMLINKS 0100
#define GET_OID_RECORD_PATH 0200
#define GET_OID_ONLY_TO_DIE 04000
+#define GET_OID_REQUIRE_PATH 010000
#define GET_OID_DISAMBIGUATORS \
(GET_OID_COMMIT | GET_OID_COMMITTISH | \
diff --git a/object-name.c b/object-name.c
index d44a8f3a7c..92862eeb1a 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1799,6 +1799,9 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0);
ret = get_oid_1(repo, name, namelen, oid, flags);
+ if (!ret && flags & GET_OID_REQUIRE_PATH)
+ die(_("<object>:<path> required, only <object> '%s' given"),
+ name);
if (!ret)
return ret;
/*
diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh
index 71ea2ac987..b067983ba1 100755
--- a/t/t8007-cat-file-textconv.sh
+++ b/t/t8007-cat-file-textconv.sh
@@ -29,7 +29,7 @@ test_expect_success 'usage: <bad rev>' '
test_expect_success 'usage: <bad rev>:<bad path>' '
cat >expect <<-\EOF &&
- fatal: Not a valid object name HEAD2:two.bin
+ fatal: invalid object name '\''HEAD2'\''.
EOF
test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
test_cmp expect actual
@@ -37,7 +37,7 @@ test_expect_success 'usage: <bad rev>:<bad path>' '
test_expect_success 'usage: <rev>:<bad path>' '
cat >expect <<-\EOF &&
- fatal: Not a valid object name HEAD:two.bin
+ fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
EOF
test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
test_cmp expect actual
@@ -46,7 +46,7 @@ test_expect_success 'usage: <rev>:<bad path>' '
test_expect_success 'usage: <rev> with no <path>' '
cat >expect <<-\EOF &&
- fatal: git cat-file --textconv HEAD: <object> must be <sha1:path>
+ fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
EOF
test_must_fail git cat-file --textconv HEAD 2>actual &&
test_cmp expect actual
@@ -55,7 +55,7 @@ test_expect_success 'usage: <rev> with no <path>' '
test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
cat >expect <<-\EOF &&
- fatal: Not a valid object name HEAD2:one.bin
+ fatal: invalid object name '\''HEAD2'\''.
EOF
test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
test_cmp expect actual