[PATCH] introduce git root

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Arjun Sreedharan <arjun024@xxxxxxxxx>
---


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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]