commit b70703ad8ae920fd55bd7976d1632e05975e5c63 from: Stefan Sperling date: Mon Mar 18 16:16:10 2019 UTC fix bugs in got_repo_map_path() and add more related tests commit - 1b3893a25b982a0bd7329a9da23581024c6ac50d commit + b70703ad8ae920fd55bd7976d1632e05975e5c63 blob - afdfaad9d4c767b121a5b9f0e740aac323254097 blob + fac0482213450d23be35c6155dd21d22aff4d48e --- lib/repository.c +++ lib/repository.c @@ -434,7 +434,6 @@ got_repo_map_path(char **in_repo_path, struct got_repo { const struct got_error *err = NULL; const char *repo_abspath = NULL; - struct stat sb; size_t repolen, cwdlen, len; char *cwd, *canonpath, *path = NULL; @@ -454,28 +453,31 @@ got_repo_map_path(char **in_repo_path, struct got_repo goto done; repo_abspath = got_repo_get_path(repo); - - /* TODO: Call "get in-repository path of work-tree node" API. */ - if (!check_disk) + if (!check_disk) { path = strdup(canonpath); - else if (lstat(canonpath, &sb) != 0) { - if (errno != ENOENT) { + if (path == NULL) { err = got_error_from_errno(); goto done; } - /* - * Path is not on disk. - * Assume it is already relative to repository root. - */ - path = strdup(canonpath); } else { int is_repo_child = 0, is_cwd_child = 0; path = realpath(canonpath, NULL); if (path == NULL) { - err = got_error_from_errno(); - goto done; + if (errno != ENOENT) { + err = got_error_from_errno(); + goto done; + } + /* + * Path is not on disk. + * Assume it is already relative to repository root. + */ + path = strdup(canonpath); + if (path == NULL) { + err = got_error_from_errno(); + goto done; + } } repolen = strlen(repo_abspath); @@ -496,7 +498,6 @@ got_repo_map_path(char **in_repo_path, struct got_repo } } else if (is_repo_child && is_cwd_child) { char *child; - /* TODO: Is path inside a got worktree? */ /* Strip common prefix with repository path. */ err = got_path_skip_common_ancestor(&child, repo_abspath, path); @@ -523,7 +524,6 @@ got_repo_map_path(char **in_repo_path, struct got_repo } } else if (is_cwd_child) { char *child; - /* TODO: Is path inside a got worktree? */ /* Strip common prefix with cwd. */ err = got_path_skip_common_ancestor(&child, cwd, path); blob - 2d890ea4314893d12659cc3245962719a2d2d08a blob + a5272f0679c901661f2534ddda6379d6a402314d --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -34,9 +34,42 @@ function test_log_in_repo { fi done + for p in "" "." zeta; do + (cd $testroot/repo/epsilon && got log $p | \ + grep ^commit > $testroot/stdout) + cmp $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + done + test_done "$testroot" "0" } +function test_log_in_bare_repo { + local testroot=`test_init log_in_bare_repo` + local head_rev=`git_show_head $testroot/repo` + + echo "commit $head_rev (master)" > $testroot/stdout.expected + + for p in "" "." alpha epsilon epsilon/zeta; do + (cd $testroot/repo/.git && got log $p | \ + grep ^commit > $testroot/stdout) + cmp $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + done + + test_done "$testroot" "0" +} + function test_log_in_worktree { local testroot=`test_init log_in_worktree` local head_rev=`git_show_head $testroot/repo` @@ -78,4 +111,5 @@ function test_log_in_worktree { } run_test test_log_in_repo +run_test test_log_in_bare_repo run_test test_log_in_worktree