commit - a3e261487a807988b92001ccb748c29465526cb3f5be0bf2c2b6de6123a1a27b
commit + a48420af0e6a32a59f5fbcc7c78fa642ca2d89a832de5aad1f6234ddf212b326
blob - c5b5dbc5f19754d24d01826a72bf2dd0402397e4082ec845347612d844de792f
blob + ef94d066eff2225f9f5b0901492bb49950a7c5e59b94cd348d4ed8ff28576594
--- lib/worktree.c
+++ lib/worktree.c
const struct got_error *err = NULL;
struct got_blob_object *blob = NULL;
char *ondisk_path = NULL;
+ const char *te_name;
unsigned char status = GOT_STATUS_NO_CHANGE;
struct stat sb;
int fd1 = -1, fd2 = -1;
int update_timestamps = 0;
+ te_name = got_tree_entry_get_name(te);
+ if (strchr(te_name, '/') != NULL ||
+ strcmp(te_name, ".") == 0 || strcmp(te_name, "..") == 0) {
+ return (*progress_cb)(progress_arg,
+ GOT_STATUS_UNVERSIONED, path);
+ }
+
err = got_fileindex_entry_relpath_allowed(path, strlen(path));
if (err) {
if (err->code != GOT_ERR_BAD_PATH)
blob - 7e2eef68ba9eebe707b274be59378b4d4205dcbcb0aef4bad77d2db8fdc006cb
blob + ad1025f67ad845290a0f53e6c175c42d6c8ccc20e00d0f3829c2ad2ff670299e
--- regress/cmdline/checkout.sh
+++ regress/cmdline/checkout.sh
test_done "$testroot" "$ret"
}
+test_checkout_bad_tree_entry() {
+ local testroot=`test_init checkout_bad_tree_entry`
+
+ (
+ cd $testroot/repo
+
+ entry() {
+ mode="$1"
+ name="$2"
+ sha="$3"
+ printf '%s %s\0' "$mode" "$name"
+ printf '%s' "$sha" | xxd -r -p
+ }
+
+ blob="$(echo 'oh no' | git hash-object -w --stdin)"
+ tree="$(entry 100644 ../pwned "$blob" | git hash-object -w -t tree --stdin --literally)"
+
+ commit="$(echo cursed | git commit-tree "$tree")"
+ git update-ref refs/heads/main "$commit"
+ git symbolic-ref HEAD refs/heads/main
+ )
+
+ local commit_id=`git_show_head $testroot/repo`
+
+ got checkout $testroot/repo $testroot/wt > $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "? $testroot/wt/../pwned" > $testroot/stdout.expected
+ echo "Checked out refs/heads/main: $commit_id" \
+ >> $testroot/stdout.expected
+ echo "Now shut up and hack" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && ls -a > $testroot/stdout)
+
+ cat > $testroot/stdout.expected <<EOF
+.
+..
+.got
+EOF
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ test_done "$testroot" "$ret" "1"
+}
+
test_parseargs "$@"
run_test test_checkout_basic
run_test test_checkout_dir_exists
run_test test_checkout_ulimit_n
run_test test_checkout_commit_keywords
run_test test_checkout_tree_with_dot_got
+run_test test_checkout_bad_tree_entry
blob - 5e90af44d2b005573818b8955cc80914d8be5488593901bcfacee351536e13df
blob + daf95edbd2da14ba542fb6d747a068556327892ee6efb0025b6469891bebf7d9
--- regress/cmdline/common.sh
+++ regress/cmdline/common.sh
test_cleanup()
{
local testroot="$1"
+ local skip_fsck="$2"
- git_fsck $testroot $testroot/repo
- ret=$?
- if [ $ret -ne 0 ]; then
- return $ret
+ if [ -z "$skip_fsck" ]; then
+ git_fsck $testroot $testroot/repo
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ return $ret
+ fi
fi
rm -rf "$testroot"
{
local testroot="$1"
local result="$2"
+ local skip_fsck="$3"
if [ "$result" = "0" ]; then
- test_cleanup "$testroot" || return 1
+ test_cleanup "$testroot" "$skip_fsck" || return 1
if [ -z "$GOT_TEST_QUIET" ]; then
echo "ok"
fi
elif echo "$result" | grep -q "^xfail"; then
# expected test failure; test reproduces an unfixed bug
echo "$result"
- test_cleanup "$testroot" || return 1
+ test_cleanup "$testroot" "$skip_fsck" || return 1
else
echo "test failed; leaving test data in $testroot"
fi