test and fix 'got revert' with a path in a sub-directory Relax input path requirements of got_object_id_by_path() to make things easier to callers. Allows the revert code to pass a path from the file index in lieu of a repository path.
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
diff --git a/lib/object.c b/lib/object.c
index 8491d04..1c9eb57 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1384,16 +1384,12 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
*id = NULL;
- /* We are expecting an absolute in-repository path. */
- if (path[0] != '/')
- return got_error(GOT_ERR_NOT_ABSPATH);
-
err = got_object_open_as_commit(&commit, repo, commit_id);
if (err)
goto done;
/* Handle opening of root of commit's tree. */
- if (path[1] == '\0') {
+ if (got_path_is_root_dir(path)) {
*id = got_object_id_dup(commit->tree_id);
if (*id == NULL)
err = got_error_from_errno("got_object_id_dup");
@@ -1405,7 +1401,8 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
goto done;
s = path;
- s++; /* skip leading '/' */
+ while (s[0] == '/')
+ s++;
seg = s;
seglen = 0;
while (*s) {
diff --git a/regress/cmdline/revert.sh b/regress/cmdline/revert.sh
index 584c34e..eec57c2 100755
--- a/regress/cmdline/revert.sh
+++ b/regress/cmdline/revert.sh
@@ -26,11 +26,11 @@ function test_revert_basic {
return 1
fi
- echo "modified alpha" > $testroot/wt/alpha
+ echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
- echo 'R alpha' > $testroot/stdout.expected
+ echo 'R epsilon/zeta' > $testroot/stdout.expected
- (cd $testroot/wt && got revert alpha > $testroot/stdout)
+ (cd $testroot/wt && got revert epsilon/zeta > $testroot/stdout)
cmp -s $testroot/stdout.expected $testroot/stdout
ret="$?"
@@ -40,8 +40,8 @@ function test_revert_basic {
return 1
fi
- echo "alpha" > $testroot/content.expected
- cat $testroot/wt/alpha > $testroot/content
+ echo "zeta" > $testroot/content.expected
+ cat $testroot/wt/epsilon/zeta > $testroot/content
cmp -s $testroot/content.expected $testroot/content
ret="$?"