From: Michael Rappazzo <rappazzo@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sunshine@sunshineco.com, pclouds@gmail.com,
Michael Rappazzo <rappazzo@gmail.com>
Subject: [PATCH v2 1/4] rev-parse: fix some options when executed from subpath of main tree
Date: Fri, 22 Apr 2016 17:53:09 -0400 [thread overview]
Message-ID: <1461361992-91918-2-git-send-email-rappazzo@gmail.com> (raw)
In-Reply-To: <1461361992-91918-1-git-send-email-rappazzo@gmail.com>
Executing `git-rev-parse` with `--git-common-dir`, `--git-path <path>`,
or `--shared-index-path` from the root of the main worktree results in
a relative path to the git dir.
When executed from a subdirectory of the main tree, however, it incorrectly
returns a path which starts 'sub/path/.git'. Change this to return the
proper relative path to the git directory.
Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
builtin/rev-parse.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index c961b74..1da2e10 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -564,10 +564,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
}
if (!strcmp(arg, "--git-path")) {
+ struct strbuf sb = STRBUF_INIT;
if (!argv[i + 1])
die("--git-path requires an argument");
- puts(git_path("%s", argv[i + 1]));
- i++;
+
+ puts(relative_path(xstrfmt("%s/%s", get_git_dir(), argv[++i]),
+ prefix, &sb));
+ strbuf_release(&sb);
continue;
}
if (as_is) {
@@ -787,8 +790,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--git-common-dir")) {
- const char *pfx = prefix ? prefix : "";
- puts(prefix_filename(pfx, strlen(pfx), get_git_common_dir()));
+ struct strbuf sb = STRBUF_INIT;
+ puts(relative_path(get_git_common_dir(), prefix, &sb));
+ strbuf_release(&sb);
continue;
}
if (!strcmp(arg, "--is-inside-git-dir")) {
@@ -811,7 +815,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
die(_("Could not read the index"));
if (the_index.split_index) {
const unsigned char *sha1 = the_index.split_index->base_sha1;
- puts(git_path("sharedindex.%s", sha1_to_hex(sha1)));
+ struct strbuf sb = STRBUF_INIT;
+
+ puts(relative_path(
+ xstrfmt("%s/sharedindex.%s", get_git_dir(), sha1_to_hex(sha1)),
+ prefix, &sb));
+ strbuf_release(&sb);
}
continue;
}
--
2.8.0
next prev parent reply other threads:[~2016-04-22 21:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 21:53 [PATCH v2 0/4] rev-parse: adjust results when they should be relative Michael Rappazzo
2016-04-22 21:53 ` Michael Rappazzo [this message]
2016-04-29 14:21 ` [PATCH v2 1/4] rev-parse: fix some options when executed from subpath of main tree SZEDER Gábor
[not found] ` <20160429135051.15492-1-szeder@ira.uka.de>
2016-05-06 13:02 ` Mike Rappazzo
2016-05-06 14:13 ` SZEDER Gábor
2016-05-06 17:08 ` Junio C Hamano
2016-05-10 7:49 ` Eric Sunshine
2016-04-22 21:53 ` [PATCH v2 2/4] t1500-rev-parse: add tests executed from sub path of the main worktree Michael Rappazzo
2016-04-29 14:22 ` SZEDER Gábor
2016-04-22 21:53 ` [PATCH v2 3/4] t2027-worktree-list: add and adjust tests related to git-rev-parse Michael Rappazzo
2016-04-29 14:22 ` SZEDER Gábor
2016-04-22 21:53 ` [PATCH v2 4/4] t1700-split-index: add test for rev-parse --shared-index-path Michael Rappazzo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461361992-91918-2-git-send-email-rappazzo@gmail.com \
--to=rappazzo@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).