fix bugs in got_repo_map_path() and add more related tests
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
diff --git a/lib/repository.c b/lib/repository.c
index afdfaad..fac0482 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -434,7 +434,6 @@ got_repo_map_path(char **in_repo_path, struct got_repository *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;
@@ -455,27 +454,30 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
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_repository *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_repository *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);
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index 2d890ea..a5272f0 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -34,6 +34,39 @@ 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"
}
@@ -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