[PATCH 14/17] commit: use commit_narrow_tree() to support narrow repo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 builtin/commit.c         |   10 +++++++++-
 t/t7510-commit-narrow.sh |   30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)
 create mode 100755 t/t7510-commit-narrow.sh

diff --git a/builtin/commit.c b/builtin/commit.c
index d8c5273..2321642 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1349,7 +1349,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		exit(1);
 	}
 
-	if (commit_tree(sb.buf, active_cache_tree->sha1, parents, commit_sha1,
+	if (get_narrow_prefix()) {
+		if (!parents)
+			die("Narrow mode does not support initial commit (yet)");
+		if (parse_commit(parents->item))
+			die("Bad commit %s", parents->item->object.sha1);
+	}
+	if (commit_narrow_tree(sb.buf, active_cache_tree->sha1,
+			parents ? parents->item->tree->object.sha1 : NULL,
+			parents, commit_sha1,
 			fmt_ident(author_name, author_email, author_date,
 				IDENT_ERROR_ON_NO_NAME))) {
 		rollback_index_files();
diff --git a/t/t7510-commit-narrow.sh b/t/t7510-commit-narrow.sh
new file mode 100755
index 0000000..1232cee
--- /dev/null
+++ b/t/t7510-commit-narrow.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+test_description='commit in narrow repositories'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	touch a b c &&
+	mkdir x y z &&
+	touch x/a y/b z/c &&
+	git add . &&
+	git commit -q -m initial &&
+	echo x >.git/narrow &&
+	rm .git/index &&
+	git reset --hard HEAD
+'
+
+X1_TREE=496d6428b9cf92981dc9495211e6e1120fb6f2ba
+X2_TREE=4d593e935186bcc35450336864a1aad148210a14
+
+test_expect_success 'commit' '
+	git ls-tree HEAD | sed "s/$X1_TREE/$X2_TREE/" >expected &&
+	echo x >>x/a &&
+	git add x/a &&
+	git commit -m x/a &&
+	git ls-tree HEAD >result &&
+	test_cmp expected result
+'
+
+test_done
-- 
1.7.1.rc1.69.g24c2f7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]