allow creation of commits which carry unmodified submodule tree entries along approach suggested by ori@ and matches how git9 behaves ok semarie@ (who can now work with Rust-related Git repos containing submodules)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/lib/object_create.c b/lib/object_create.c
index 515477b..fa3eec2 100644
--- a/lib/object_create.c
+++ b/lib/object_create.c
@@ -202,7 +202,7 @@ done:
}
static const struct got_error *
-te_mode2str(char *buf, size_t len, mode_t te_mode)
+te_mode2str(char *buf, size_t len, struct got_tree_entry *te)
{
int ret;
mode_t mode;
@@ -210,13 +210,15 @@ te_mode2str(char *buf, size_t len, mode_t te_mode)
/*
* Some Git implementations are picky about modes seen in tree entries.
* For best compatibility we normalize the file/directory mode here.
- * Note that we do not support committing symlinks or submodules.
+ * Note that we do not support committing symlinks.
*/
- if (S_ISREG(te_mode)) {
+ if (S_ISREG(te->mode)) {
mode = GOT_DEFAULT_FILE_MODE;
- if (te_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
+ if (te->mode & (S_IXUSR | S_IXGRP | S_IXOTH))
mode |= S_IXUSR | S_IXGRP | S_IXOTH;
- } else if (S_ISDIR(te_mode))
+ } else if (got_object_tree_entry_is_submodule(te))
+ mode = S_IFDIR | S_IFLNK;
+ else if (S_ISDIR(te->mode))
mode = S_IFDIR; /* Git leaves all the other bits unset. */
else
return got_error(GOT_ERR_BAD_FILETYPE);
@@ -281,7 +283,7 @@ got_object_tree_create(struct got_object_id **id,
for (i = 0; i < nentries; i++) {
te = sorted_entries[i];
- err = te_mode2str(modebuf, sizeof(modebuf), te->mode);
+ err = te_mode2str(modebuf, sizeof(modebuf), te);
if (err)
goto done;
len += strlen(modebuf) + strlen(te->name) + 1 +
@@ -309,7 +311,7 @@ got_object_tree_create(struct got_object_id **id,
for (i = 0; i < nentries; i++) {
te = sorted_entries[i];
- err = te_mode2str(modebuf, sizeof(modebuf), te->mode);
+ err = te_mode2str(modebuf, sizeof(modebuf), te);
if (err)
goto done;
len = strlen(modebuf);
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index 3c8e833..edfc2bb 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -873,28 +873,31 @@ function test_commit_with_unrelated_submodule {
got checkout $testroot/repo $testroot/wt > /dev/null
ret="$?"
if [ "$ret" != "0" ]; then
+ echo "checkout failed unexpectedly" >&2
test_done "$testroot" "$ret"
return 1
fi
echo "modified alpha" > $testroot/wt/alpha
- # Currently fails with "bad file type" error
- (cd $testroot/wt && got commit -m 'modify alpha' \
- > $testroot/stdout 2> $testroot/stderr)
+ echo "" > $testroot/stdout.expected
+
+ cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout
ret="$?"
- if [ "$ret" == "0" ]; then
- echo "commit succeeded unexpectedly" >&2
- test_done "$testroot" "1"
+ if [ "$ret" != "0" ]; then
+ echo "commit failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
return 1
fi
- echo "got: bad file type" > $testroot/stderr.expected
- cmp -s $testroot/stderr.expected $testroot/stderr
+ local head_rev=`git_show_head $testroot/repo`
+ echo "M alpha" > $testroot/stdout.expected
+ echo "Created commit $head_rev" >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
if [ "$ret" != "0" ]; then
- diff -u $testroot/stderr.expected $testroot/stderr
- return 1
+ diff -u $testroot/stdout.expected $testroot/stdout
fi
test_done "$testroot" "$ret"
}