git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] introduce git root

From
Arjun Sreedharan <arjun024@gmail.com>
Date
Nov 30, 2014, 04:35 UTC
Message-ID
<CAJFMrCEciWXhBb36MVeFPi7Y7D=9zQ2xGPpiyUz9y4_hOh_taw@mail.gmail.com>
In-Reply-To
<2AC7B765F56B4AA8A0DB76E8C670A889@PhilipOakley>
On 30 November 2014 at 04:38, Philip Oakley <philipoakley@iee.org> wrote:
Show 12 quoted lines
> From: "Arjun Sreedharan" <arjun024@gmail.com>
>>
>> This introduces `git root` which outputs the root directory
>> (the directory that contains .git).
>> The same can be accomplished by `git rev-parse --show-toplevel`.
>> `git root` is much more intuitive and easy to remember.
>> All it does is set the arguments for rev-parse
>
>
> This may be better as an alias.
> I've added it to my aliases list.
>

I know that. I am suggesting this to be a built-in command, without having the need to add as an alias.

Show 89 quoted lines
>>
>> Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
>> ---
>>
>>
>> Hi,
>> I don't know if I can just send a patch for a new "command" in git,
>> I probably shouldn't. Well, i thought it's anyway better explaining
>> this way than just asking for comments.
>>
>> With the kind of projects i have been involved with in the recent past, I
>> have had to deal with subprojects inside projects and for many reasons had
>> to find ways to find the root git folder and at times to "cd" to it.
>>
>> The obvious choice is to go for `git rev-parse --show-toplevel`. But, this
>> to me doesn't seem very _intuitive_ and `git root` does.
>> bzr has `bzr root`. hg has `hg root`. So, for programmers i am guessing
>> this pattern would also be _instinctive_, and i am thinking why not `git
>> root`?
>> Arjun Sreedharan
>>
>>
>>
>> Makefile       |  1 +
>> builtin.h      |  1 +
>> builtin/root.c | 10 ++++++++++
>> git.c          |  1 +
>> 4 files changed, 13 insertions(+)
>> create mode 100644 builtin/root.c
>>
>> diff --git a/Makefile b/Makefile
>> index 827006b..7f28d13 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -869,6 +869,7 @@ BUILTIN_OBJS += builtin/rev-list.o
>> BUILTIN_OBJS += builtin/rev-parse.o
>> BUILTIN_OBJS += builtin/revert.o
>> BUILTIN_OBJS += builtin/rm.o
>> +BUILTIN_OBJS += builtin/root.o
>> BUILTIN_OBJS += builtin/send-pack.o
>> BUILTIN_OBJS += builtin/shortlog.o
>> BUILTIN_OBJS += builtin/show-branch.o
>> diff --git a/builtin.h b/builtin.h
>> index b87df70..4672d72 100644
>> --- a/builtin.h
>> +++ b/builtin.h
>> @@ -112,6 +112,7 @@ extern int cmd_rev_list(int argc, const char **argv,
>> const char *prefix);
>> extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
>> extern int cmd_revert(int argc, const char **argv, const char *prefix);
>> extern int cmd_rm(int argc, const char **argv, const char *prefix);
>> +extern int cmd_root(int argc, const char **argv, const char *prefix);
>> extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
>> extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
>> extern int cmd_show(int argc, const char **argv, const char *prefix);
>> diff --git a/builtin/root.c b/builtin/root.c
>> new file mode 100644
>> index 0000000..c2eeca3
>> --- /dev/null
>> +++ b/builtin/root.c
>> @@ -0,0 +1,10 @@
>> +#include "builtin.h"
>> +#include "argv-array.h"
>> +
>> +int cmd_root(int argc, const char **argv, const char *prefix)
>> +{
>> + struct argv_array root_args = ARGV_ARRAY_INIT;
>> +
>> + argv_array_pushl(&root_args, argv[0], "--show-toplevel", NULL);
>> + return cmd_rev_parse(root_args.argc, root_args.argv, prefix);
>> +}
>> diff --git a/git.c b/git.c
>> index 18fbf79..6a0be5f 100644
>> --- a/git.c
>> +++ b/git.c
>> @@ -461,6 +461,7 @@ static struct cmd_struct commands[] = {
>>  { "rev-parse", cmd_rev_parse },
>>  { "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
>>  { "rm", cmd_rm, RUN_SETUP },
>> + { "root", cmd_root, RUN_SETUP },
>>  { "send-pack", cmd_send_pack, RUN_SETUP },
>>  { "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
>>  { "show", cmd_show, RUN_SETUP },
>> --
>> 1.7.11.7
>>
>> --
>
> Philip
Previous: Philip OakleyNext: Matthieu Moy
Message 3 of 23 in “introduce git root”
  1. introduce git rootArjun Sreedharan, Nov 29, 2014
  2. Philip OakleyNov 29, 2014
  3. Arjun SreedharanNov 30, 2014
  4. Matthieu MoyNov 30, 2014
  5. Junio C HamanoDec 1, 2014
  6. Christian CouderDec 1, 2014
  7. Junio C HamanoDec 1, 2014
  8. Jeff KingDec 2, 2014
  9. Christian CouderDec 2, 2014
  10. Junio C HamanoDec 2, 2014
  11. Jeff KingDec 4, 2014
  12. Junio C HamanoDec 4, 2014
  13. Matthieu MoyDec 4, 2014
  14. Junio C HamanoDec 4, 2014
  15. Jeff KingDec 4, 2014
  16. Junio C HamanoDec 4, 2014
  17. Christian CouderDec 5, 2014
  18. Jeff KingDec 5, 2014
  19. Christian CouderDec 7, 2014
  20. Junio C HamanoDec 9, 2014
  21. Christian CouderDec 10, 2014
  22. Jeff KingDec 10, 2014
  23. Junio C HamanoDec 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.