worktree: add functions to get name and path#4640
Conversation
tiennou
left a comment
There was a problem hiding this comment.
Looks better, thanks for that. A few style issue left, as well as some leaks in the testsuite.
| * | ||
| * @param wt Worktree to get the name for | ||
| * @return The worktree's name. The pointer returned is valid for the | ||
| * lifetime of the git_worktree |
There was a problem hiding this comment.
Nitpick: still a stray space here.
| * | ||
| * @param wt Worktree to get the path for | ||
| * @return The worktree's filesystem path. The pointer returned | ||
| * is valid for the lifetime of the git_worktree. |
| return ret; | ||
| } | ||
|
|
||
| const char * git_worktree_name(const git_worktree *wt) |
There was a problem hiding this comment.
Nitpick: no space after *.
| return wt->name; | ||
| } | ||
|
|
||
| const char * git_worktree_path(const git_worktree *wt) |
|
|
||
| if (is_valid_tmp_path(env)) { | ||
| #ifdef __APPLE__ | ||
| if ( length >= PATH_MAX && realpath(env, buffer) != NULL ) |
There was a problem hiding this comment.
Nitpick: no spaces inside braces.
| /* If the environment doesn't say anything, try to use /tmp */ | ||
| if (is_valid_tmp_path("/tmp")) { | ||
| #ifdef __APPLE__ | ||
| if ( length >= PATH_MAX && realpath("/tmp", buffer) != NULL ) |
|
|
||
| cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); | ||
| cl_assert_equal_s(git_worktree_name(wt), "testrepo-worktree"); | ||
| } |
There was a problem hiding this comment.
Missing git_worktree_free.
| cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr); | ||
|
|
||
| git_buf_free(&expected_path); | ||
| } |
|
Don't have time to 👀 this just yet, but I wanted to make two quick comments from your prior PR:
This has definitely come up before, I'll have to look through some things for context.
Generally it's easier for us to review one PR instead of two. Feel free to iterate in the PR. |
cf42005 to
3da1ad2
Compare
|
@ethomson Yeah, I wasn't so sure about how github would respond to a PR being updated with forced pushes with rewritten commits. It seems to work well enough though so I definitely should have done it for the other PR. |
|
Thanks again for this PR! |
This is a reworking of my previous PR to clean up some commit history
This adds two new functions:
git_worktree_name- retrieves the name from agit_worktreegit_worktree_path- retrieves the location on the file system from agit_worktree