On 2020-09-09 at 14:51:14, SZEDER Gábor wrote: > On Tue, Sep 08, 2020 at 06:50:17PM +0000, brian m. carlson wrote: > > diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt > > index 19b12b6d43..6b95292559 100644 > > --- a/Documentation/git-rev-parse.txt > > +++ b/Documentation/git-rev-parse.txt > > @@ -208,6 +208,15 @@ Options for Files > > Only the names of the variables are listed, not their value, > > even if they are set. > > > > +--path-format=(absolute|relative):: > > + Controls the behavior of certain other options following it on the command > > + line. > > Does it affect only one subsequent such option on the command line, or > all such options? IOW, while standing in the top directory of the > worktree, would the following command > > git rev-parse --path-format=absolute --git-dir --git-path foo --show-toplevel > > print three absolute paths, or one absolute paths and two relative > paths? > > The wording here is not clear on this, the commit message doesn't > mention it, and the tests added in this patch only check one such > option, but looking at the code and doing some testing of my own I > found that it affects all subsequent such options. It affects all subsequent options. Moreover, I believe it's possible to switch in the middle of the command line if you want some things relative and some absolute. That seemed to be both the easiest solution and the most flexible, so I went with it. I'll add more tests for this case and improve the commit message. > > diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh > > index 408b97d5af..6f3811d189 100755 > > --- a/t/t1500-rev-parse.sh > > +++ b/t/t1500-rev-parse.sh > > @@ -3,6 +3,16 @@ > > test_description='test git rev-parse' > > . ./test-lib.sh > > > > +test_one () { > > + dir="$1" && > > + expect="$2" && > > + shift && > > + shift && > > + echo "$expect" >expect && > > + git -C "$dir" rev-parse "$@" >actual > > Broken && chain. Thanks, will fix. > > + test_cmp expect actual > > +} > > + > > # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir > > test_rev_parse () { > > d= > > @@ -60,7 +70,13 @@ ROOT=$(pwd) > > > > test_expect_success 'setup' ' > > mkdir -p sub/dir work && > > - cp -R .git repo.git > > + cp -R .git repo.git && > > + git checkout -b main && > > + test_commit abc && > > + git checkout -b side && > > + test_commit def && > > + git checkout main && > > + git worktree add worktree side > > ' > > > > test_rev_parse toplevel false false true '' .git "$ROOT/.git" > > @@ -88,6 +104,24 @@ test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = tru > > > > test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true '' > > > > +test_expect_success 'rev-parse --path-format=absolute' ' > > + test_one "." "$ROOT/.git" --path-format=absolute --git-dir && > > + test_one "." "$ROOT/.git" --path-format=absolute --git-common-dir && > > + test_one "worktree" "$ROOT/.git/worktrees/worktree" --path-format=absolute --git-dir && > > + test_one "worktree" "$ROOT/.git" --path-format=absolute --git-common-dir && > > + test_one "." "$ROOT" --path-format=absolute --show-toplevel && > > + test_one "." "$ROOT/.git/objects" --path-format=absolute --git-path objects > > +' > > + > > +test_expect_success 'rev-parse --path-format=relative' ' > > + test_one "." ".git" --path-format=relative --git-dir && > > + test_one "." ".git" --path-format=relative --git-common-dir && > > + test_one "worktree" "../.git/worktrees/worktree" --path-format=relative --git-dir && > > + test_one "worktree" "../.git" --path-format=relative --git-common-dir && > > + test_one "." "./" --path-format=relative --show-toplevel && > > + test_one "." ".git/objects" --path-format=relative --git-path objects > > +' > > I would like to see a test that demonstrates that '--absolute-git-dir' > is unaffected by '--path-format=relative', just to be sure. > > There are some cases where this new option doesn't do what I would > expect: > > $ ./git -C Documentation/ rev-parse --git-dir --show-toplevel > /home/szeder/src/git/.git > /home/szeder/src/git > $ ./git -C Documentation/ rev-parse --path-format=absolute --git-dir --show-toplevel > /home/szeder/src/git/.git > /home/szeder/src/git > # So far so good, but: > $ ./git -C Documentation/ rev-parse --path-format=relative --git-dir --show-toplevel > /home/szeder/src/git/.git > /home/szeder/src/git > > > $ ls -l .git/foo > ls: cannot access '.git/foo': No such file or directory > $ ./git rev-parse --git-path foo > .git/foo > $ ./git rev-parse --path-format=relative --git-path foo > .git/foo > $ ./git rev-parse --path-format=absolute --git-path foo > /home/szeder/src/git/.git/foo > $ ./git rev-parse --git-path foo/bar > .git/foo/bar > $ ./git rev-parse --path-format=relative --git-path foo/bar > .git/foo/bar > # So far so good, but: > $ ./git rev-parse --path-format=absolute --git-path foo/bar > fatal: Invalid path '/home/szeder/src/git/.git/foo': No such file or directory That's going to be a little tricky to fix, but I'll look into it. -- brian m. carlson: Houston, Texas, US
Attachment:
signature.asc
Description: PGP signature