summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 801cfae)
raw | patch | inline | side by side (parent: 801cfae)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 10 May 2009 18:30:03 +0000 (11:30 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 11 May 2009 00:31:01 +0000 (17:31 -0700) |
We need to allow input lines that point at objects that we do not
have when dealing with submodule entries anyway. This adds an explicit
option to allow missing objects of other types, to be consistent with
the use of --info-only option to the update-index command and --missing-ok
option to the write-tree command.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
have when dealing with submodule entries anyway. This adds an explicit
option to allow missing objects of other types, to be consistent with
the use of --info-only option to the update-index command and --missing-ok
option to the write-tree command.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-mktree.c | patch | blob | history | |
t/t1010-mktree.sh | patch | blob | history |
diff --git a/builtin-mktree.c b/builtin-mktree.c
index 17cdb3d63a79cbf113151d53b6d2bf280a1045a3..e1c9a2701adf4e692385336a764003b28134067d 100644 (file)
--- a/builtin-mktree.c
+++ b/builtin-mktree.c
NULL
};
-static void mktree_line(char *buf, size_t len, int line_termination)
+static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing)
{
char *ptr, *ntr;
unsigned mode;
die("input format error: %s", buf);
/* It is perfectly normal if we do not have a commit from a submodule */
- if (!S_ISGITLINK(mode))
+ if (S_ISGITLINK(mode))
+ allow_missing = 1;
+
+ if (!allow_missing)
type = sha1_object_info(sha1, NULL);
else
- type = OBJ_COMMIT;
+ type = object_type(mode);
if (type < 0)
die("object %s unavailable", sha1_to_hex(sha1));
struct strbuf sb = STRBUF_INIT;
unsigned char sha1[20];
int line_termination = '\n';
+ int allow_missing = 0;
const struct option option[] = {
OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
+ OPT_SET_INT( 0 , "missing", &allow_missing, "allow missing objects", 1),
OPT_END()
};
ac = parse_options(ac, av, option, mktree_usage, 0);
while (strbuf_getline(&sb, stdin, line_termination) != EOF)
- mktree_line(sb.buf, sb.len, line_termination);
+ mktree_line(sb.buf, sb.len, line_termination, allow_missing);
strbuf_release(&sb);
diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh
index 4d9b1383c67d2a736899ca3e52c99608bdb7724c..9956e3ad625eb1d70789538ecdb55e318669bdf9 100755 (executable)
--- a/t/t1010-mktree.sh
+++ b/t/t1010-mktree.sh
mkdir "$d" && echo "$d/one" >"$d/one" &&
git add "$d"
done &&
+ echo zero >one &&
+ git update-index --add --info-only one &&
+ git write-tree --missing-ok >tree.missing &&
+ git ls-tree $(cat tree.missing) >top.missing &&
+ git ls-tree -r $(cat tree.missing) >all.missing &&
echo one >one &&
git add one &&
git write-tree >tree &&
test_cmp tree.withsub actual
'
+test_expect_success 'allow missing object with --missing' '
+ git mktree --missing <top.missing >actual &&
+ test_cmp tree.missing actual
+'
+
test_expect_failure 'mktree reads ls-tree -r output (1)' '
git mktree <all >actual &&
test_cmp tree actual