Re: [GSoC Patch v7 8/8] repo: add path.cdup
- From
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
- Date
- Nov 3, 2026, 02:54 UTC
- Message-ID
- <CA+rGoLd7=sx61dWcC6RFD-Q-88KNd9YgEES-jLDqiTmKMMLf9g@mail.gmail.com>
- In-Reply-To
- <aukYVs2nVla0yuSV@denethor>
On Tue, Nov 3, 2026 at 4:50 AM Justin Tobler <jltobler@gmail.com> wrote:
Show 18 quoted lines
>
> On 26/09/27 05:14PM, K Jayatheerth wrote:
> [snip]
> > +static int get_path_cdup(struct repository *repo, struct strbuf *buf)
> > +{
> > + const char *pfx = repo->prefix;
> > +
> > + if (!is_inside_work_tree(repo)) {
> > + const char *worktree = repo_get_work_tree(repo);
> > +
> > + if (worktree) {
> > + strbuf_addstr(buf, worktree);
> > + }
>
> nit: The curly braces on a single line if statement are not needed.
>
> Also, should we just return early if we are not inside a worktree?
>We should just return early. You are right. I will do that.
Show 21 quoted lines
> > + }
> > +
> > + while (pfx) {
> > + pfx = strchr(pfx, '/');
> > + if (pfx) {
> > + pfx++;
> > + strbuf_addstr(buf, "../");
> > + }
> > + }
> > + return 0;
> > +}
> > +
> [snip]
> > +test_expect_success 'path.cdup cwd outside the working tree' '
> > + test_when_finished "rm -rf repo" &&
> > + mkdir -p repo/tmp/x &&
> > + cd repo &&
>
> This cd isn't in a subshell, so it changes the working directory for
> every following test, which I don't think was intended.
>Oh whoops, that wasn't intended. Yeah this clearly just cds into non test env altering common files.
Will fix it.
Show 13 quoted lines
> > + git init test && > > + ( > > + echo path.cdup=$(pwd)/tmp/x >./test/expect && > > + cd test && > > + GIT_WORK_TREE=../tmp/x && > > + export GIT_WORK_TREE && > > + GIT_DIR=$(pwd)/.git && > > + export GIT_DIR && > > + git repo info path.cdup >actual && > > + test_cmp expect actual > > + ) > > -Justin
Thank you for the review!
- K Jayatheerth