commit e8863bdcc347433dd57e74d456115a6cb5d9953c from: Stefan Sperling date: Thu Jul 23 14:22:33 2020 UTC add symlink support to 'got import' commit - 993e2a1b1ac61a9d56877df5325d519f7b737375 commit + e8863bdcc347433dd57e74d456115a6cb5d9953c blob - dec92533e2bad4d1d830b4d80f307bdc5314cb8a blob + 6234533b470b15cee07c5edc3c6b9beb606bcda1 --- lib/repository.c +++ lib/repository.c @@ -1454,7 +1454,12 @@ alloc_added_blob_tree_entry(struct got_tree_entry **ne goto done; } - (*new_te)->mode = S_IFREG | (mode & ((S_IRWXU | S_IRWXG | S_IRWXO))); + if (S_ISLNK(mode)) { + (*new_te)->mode = S_IFLNK; + } else { + (*new_te)->mode = S_IFREG; + (*new_te)->mode |= (mode & (S_IRWXU | S_IRWXG | S_IRWXO)); + } memcpy(&(*new_te)->id, blob_id, sizeof((*new_te)->id)); done: if (err && *new_te) { @@ -1607,7 +1612,7 @@ write_tree(struct got_object_id **new_tree_id, const c err = NULL; continue; } - } else if (type == DT_REG) { + } else if (type == DT_REG || type == DT_LNK) { err = import_file(&new_te, de, path_dir, repo); if (err) goto done; @@ -1628,7 +1633,7 @@ write_tree(struct got_object_id **new_tree_id, const c TAILQ_FOREACH(pe, &paths, entry) { struct got_tree_entry *te = pe->data; char *path; - if (!S_ISREG(te->mode)) + if (!S_ISREG(te->mode) && !S_ISLNK(te->mode)) continue; if (asprintf(&path, "%s/%s", path_dir, pe->path) == -1) { err = got_error_from_errno("asprintf"); blob - 5104375e287f0e845051a912863028d3e6a4d86c blob + bc744fcb7fa87573ecc329d19d9b5140d79d7444 --- regress/cmdline/common.sh +++ regress/cmdline/common.sh @@ -156,7 +156,8 @@ function get_blob_id tree_path="$2" filename="$3" - got tree -r $repo -i $tree_path | grep ${filename}$ | cut -d' ' -f 1 + got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \ + cut -d' ' -f 1 } function test_init blob - a5da67ca967c91f73507031c7e592c80f772a371 blob + 82df005b32ffe2f974cea0f4b8d19ac3638ce010 --- regress/cmdline/import.sh +++ regress/cmdline/import.sh @@ -241,7 +241,58 @@ function test_import_empty_dir { test_done "$testroot" "$ret" } +function test_import_symlink { + local testname=import_symlink + local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX` + + got init $testroot/repo + + mkdir $testroot/tree + echo 'this is file alpha' > $testroot/tree/alpha + ln -s alpha $testroot/tree/alpha.link + + got import -m 'init' -r $testroot/repo $testroot/tree \ + > $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + return 1 + fi + + local head_commit=`git_show_head $testroot/repo` + echo "A $testroot/tree/alpha" > $testroot/stdout.expected + echo "A $testroot/tree/alpha.link" >> $testroot/stdout.expected + echo "Created branch refs/heads/main with commit $head_commit" \ + >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + id_alpha=`get_blob_id $testroot/repo "" alpha` + id_alpha_link=$(got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1) + tree_id=`(cd $testroot/repo && got cat $head_commit | \ + grep ^tree | cut -d ' ' -f 2)` + + got tree -i -r $testroot/repo -c $head_commit > $testroot/stdout + + echo "$id_alpha alpha" > $testroot/stdout.expected + echo "$id_alpha_link alpha.link@ -> alpha" >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + run_test test_import_basic run_test test_import_requires_new_branch run_test test_import_ignores run_test test_import_empty_dir +run_test test_import_symlink