Skip to content

Conversation

jdblischak
Copy link
Contributor

I was testing out the function ls_tree() and observed some strange behavior. I noticed that the tests in tests/tree.R did not cover the use cases described in man/ls_tree.Rd. Specifically, the presence of a subfolder gives ls_tree() problems.

This PR converts the examples from ?ls_tree into a test file. It also adds additional tests corresponding to the results of git ls-tree.

To compare, below is the output of git ls-tree -lr HEAD. There are 3 lines corresponding to the 3 files in the repository.

$ git ls-tree -lr HEAD
100644 blob 4c5fd919d52e3c1b08f7924cfa05d6de100912fd      11    example-1.txt
100644 blob f89598da398eb016c504a5e272cb3eb1a31e2687      11    example-3.txt
100644 blob 20d5b672a347112783818b3fc8cc7cd66ade3008      12    subfolder/example-2.txt

In contrast, ls_tree() returns 4 lines. It includes the tree subfolder as its own line, and then the final line does not include the file inside the subfolder.

ls_tree(repo = repo)
    mode type                                      sha path          name   len
1 100644 blob 4c5fd919d52e3c1b08f7924cfa05d6de100912fd      example-1.txt    11
2 100644 blob f89598da398eb016c504a5e272cb3eb1a31e2687      example-3.txt    11
3 040000 tree 10cf266f7fd804e61b37419841a45699bc6fe74b          subfolder    NA
4                                                                         21899

Lastly, I found it strange that the argument tree accepts the characters "HEAD:subfolder" and "HEAD:", but not "HEAD".

> ls_tree(tree = "HEAD:", repo = repo)
    mode type                                      sha path          name   len
1 100644 blob 4c5fd919d52e3c1b08f7924cfa05d6de100912fd      example-1.txt    11
2 100644 blob f89598da398eb016c504a5e272cb3eb1a31e2687      example-3.txt    11
3 040000 tree 10cf266f7fd804e61b37419841a45699bc6fe74b          subfolder    NA
4                                                                         21899
> ls_tree(tree = "HEAD", repo = repo)
Error in data.frame(.Call(git2r_tree_walk, tree, recursive), stringsAsFactors = FALSE) : 
  Error in 'git2r_tree_walk': 'tree' must be an S3 class git_tree

Signed-off-by: John Blischak <jdblischak@gmail.com>
stewid added a commit that referenced this pull request Oct 31, 2019
The presence of a subfolder gives ls_tree() problems, see description
in PR #402

Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
stewid added a commit that referenced this pull request Oct 31, 2019
Make it possible for the tree argument to reference a commit, for
example, "HEAD", see example in PR #402.

Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
@stewid stewid merged commit 3510043 into ropensci:master Oct 31, 2019
@stewid
Copy link
Member

stewid commented Oct 31, 2019

I have finally come around to fix the problems you identified in 'ls_tree' - apologies for the delay.
Thanks.

@jdblischak
Copy link
Contributor Author

Thanks! I tested and confirmed that ls_tree() now gives results similar to git ls-tree -lr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants