From 025e7ba7fd1178fa56eca17a695a169d01beefc6 Mon Sep 17 00:00:00 2001 From: Abimbola Date: Wed, 30 Oct 2019 12:14:36 +0100 Subject: [PATCH 1/5] psuh: add a built-in by popular demand Internal metrics indicate this is a command many users expect to be present. So here's an implementation to help drive customer satisfaction and engagement: a pony which doubtfully greets the user, or, a Pony Saying "Um, Hello" (PSUH). This commit message is intentionally formatted to 72 columns per line, starts with a single line as "commit message subject" that is written as if to command the codebase to do something (add this, teach a command that). The body of the message is designed to add information about the commit that is not readily deduced from reading the associated diff, such as answering the question "why?". Signed-off-by: Abimbola --- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/psuh.c | 7 +++++++ git.c | 1 + 5 files changed, 11 insertions(+) create mode 100644 builtin/psuh.c diff --git a/.gitignore b/.gitignore index 89b3b79c1a2278..90364d5975d6a0 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,7 @@ /git-patch-id /git-prune /git-prune-packed +/git-psuh /git-pull /git-push /git-quiltimport diff --git a/Makefile b/Makefile index 58b92af54b2af4..3533b6b4da6b71 100644 --- a/Makefile +++ b/Makefile @@ -1102,6 +1102,7 @@ BUILTIN_OBJS += builtin/pack-refs.o BUILTIN_OBJS += builtin/patch-id.o BUILTIN_OBJS += builtin/prune-packed.o BUILTIN_OBJS += builtin/prune.o +BUILTIN_OBJS += builtin/psuh.o BUILTIN_OBJS += builtin/pull.o BUILTIN_OBJS += builtin/push.o BUILTIN_OBJS += builtin/range-diff.o diff --git a/builtin.h b/builtin.h index 5cf5df69f72fd5..289d9c28b98340 100644 --- a/builtin.h +++ b/builtin.h @@ -201,6 +201,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix); int cmd_patch_id(int argc, const char **argv, const char *prefix); int cmd_prune(int argc, const char **argv, const char *prefix); int cmd_prune_packed(int argc, const char **argv, const char *prefix); +int cmd_psuh(int argc, const char **argv, const char *prefix); int cmd_pull(int argc, const char **argv, const char *prefix); int cmd_push(int argc, const char **argv, const char *prefix); int cmd_range_diff(int argc, const char **argv, const char *prefix); diff --git a/builtin/psuh.c b/builtin/psuh.c new file mode 100644 index 00000000000000..1b847baf46f4c6 --- /dev/null +++ b/builtin/psuh.c @@ -0,0 +1,7 @@ +#include "builtin.h" + +int cmd_psuh(int argc, const char **argv, const char *prefix) +{ + printf(_("Pony saying hello goes here.\n")); + return 0; +} \ No newline at end of file diff --git a/git.c b/git.c index ce6ab0ece2cc6d..e92992307befa5 100644 --- a/git.c +++ b/git.c @@ -546,6 +546,7 @@ static struct cmd_struct commands[] = { { "pickaxe", cmd_blame, RUN_SETUP }, { "prune", cmd_prune, RUN_SETUP }, { "prune-packed", cmd_prune_packed, RUN_SETUP }, + { "psuh", cmd_psuh, RUN_SETUP }, { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE }, { "push", cmd_push, RUN_SETUP }, { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER }, From a1739d2cbb125d274777787222cde3ad41a702d2 Mon Sep 17 00:00:00 2001 From: Abimbola Date: Wed, 30 Oct 2019 12:45:42 +0100 Subject: [PATCH 2/5] psuh: show parameters & config opts Signed-off-by: Abimbola --- builtin/psuh.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index 1b847baf46f4c6..cdc69daeb8d887 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,7 +1,26 @@ #include "builtin.h" +#include "config.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { - printf(_("Pony saying hello goes here.\n")); + const char *cfg_name; + int i; + printf(_("Pony saying hello goes here.\n")); + + printf(Q_("Your args (there is %d):\n", + "Your args (there are %d):\n", + argc), + argc); + for (i = 0; i < argc; i++) + printf("%d: %s\n", i, argv[i]); + + printf(_("Your current working directory:\n%s%s\n"), + prefix ? "/" : "", prefix ? prefix : ""); + + git_config(git_default_config, NULL); + if (git_config_get_string_const("user.name", &cfg_name) > 0) + printf(_("No name is found in config\n")); + else + printf(_("Your name: %s\n"), cfg_name); return 0; } \ No newline at end of file From d8951c84405ce15adaeb64801c3738fb7a7858f1 Mon Sep 17 00:00:00 2001 From: Abimbola Date: Wed, 30 Oct 2019 13:10:18 +0100 Subject: [PATCH 3/5] psuh: print the current branch Signed-off-by: Abimbola --- builtin/psuh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index cdc69daeb8d887..c643d88897260d 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,10 +1,12 @@ #include "builtin.h" #include "config.h" +#include "wt-status.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { const char *cfg_name; int i; + struct wt_status status; printf(_("Pony saying hello goes here.\n")); printf(Q_("Your args (there is %d):\n", @@ -16,11 +18,18 @@ int cmd_psuh(int argc, const char **argv, const char *prefix) printf(_("Your current working directory:\n%s%s\n"), prefix ? "/" : "", prefix ? prefix : ""); - + git_config(git_default_config, NULL); if (git_config_get_string_const("user.name", &cfg_name) > 0) printf(_("No name is found in config\n")); else printf(_("Your name: %s\n"), cfg_name); + + wt_status_prepare(the_repository, &status); + git_config(git_default_config, &status); + + printf(_("Your current branch: %s\n"), status.branch); + + return 0; } \ No newline at end of file From fffdf9fd4f390bfdc65ef4edc9da155df9b36611 Mon Sep 17 00:00:00 2001 From: Abimbola Date: Wed, 30 Oct 2019 13:58:13 +0100 Subject: [PATCH 4/5] create help documentation Signed-off-by: Abimbola --- Documentation/git-psuh.txt | 32 ++++++++++++++++++++++++++++++++ builtin/psuh.c | 12 +++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Documentation/git-psuh.txt diff --git a/Documentation/git-psuh.txt b/Documentation/git-psuh.txt new file mode 100644 index 00000000000000..4e4840f4b15457 --- /dev/null +++ b/Documentation/git-psuh.txt @@ -0,0 +1,32 @@ +git-psuh(1) +=========== + +NAME +---- +git-psuh - Delight users' typo with a shy horse + + +SYNOPSIS +-------- +[verse] +'git-psuh [...]' + +DESCRIPTION +----------- +For Outreachy First Contribution + +OPTIONS[[OPTIONS]] +------------------ +None + +OUTPUT +------ +Display the following OUTPUT +-- Current Directory +-- User Name +-- Current Branch +-- Current Commit + +GIT +--- +Part of the git[1] suite \ No newline at end of file diff --git a/builtin/psuh.c b/builtin/psuh.c index c643d88897260d..f19e801101d291 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -1,12 +1,17 @@ #include "builtin.h" #include "config.h" #include "wt-status.h" +#include "commit.h" +#include "pretty.h" int cmd_psuh(int argc, const char **argv, const char *prefix) { const char *cfg_name; int i; struct wt_status status; + struct commit *c = NULL; + struct strbuf commitline = STRBUF_INIT; + printf(_("Pony saying hello goes here.\n")); printf(Q_("Your args (there is %d):\n", @@ -30,6 +35,11 @@ int cmd_psuh(int argc, const char **argv, const char *prefix) printf(_("Your current branch: %s\n"), status.branch); - + c = lookup_commit_reference_by_name("origin/master"); + + if (c != NULL) { + pp_commit_easy(CMIT_FMT_ONELINE, c, &commitline); + printf(_("Current commit: %s\n"), commitline.buf); + } return 0; } \ No newline at end of file From a0b846e9fd72ee03117640e54ac74b09715ada1c Mon Sep 17 00:00:00 2001 From: Abimbola Date: Wed, 30 Oct 2019 15:32:05 +0100 Subject: [PATCH 5/5] create usage option Signed-off-by: Abimbola --- builtin/psuh.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/builtin/psuh.c b/builtin/psuh.c index f19e801101d291..8f4f12538ead23 100644 --- a/builtin/psuh.c +++ b/builtin/psuh.c @@ -3,14 +3,24 @@ #include "wt-status.h" #include "commit.h" #include "pretty.h" +#include "parse-options.h" + +static const char *const psuh_usage[] = { + N_("git psuh [...]"), + NULL, +}; + int cmd_psuh(int argc, const char **argv, const char *prefix) { + int i; const char *cfg_name; - int i; - struct wt_status status; - struct commit *c = NULL; + struct wt_status status; + struct commit *c = NULL; struct strbuf commitline = STRBUF_INIT; + struct option options[] = { OPT_END() }; + + argc = parse_options(argc, argv, prefix, options, psuh_usage, 0); printf(_("Pony saying hello goes here.\n"));