diff --git a/Documentation/git-psuh.adoc b/Documentation/git-psuh.adoc new file mode 100644 index 00000000000000..395358e0f63430 --- /dev/null +++ b/Documentation/git-psuh.adoc @@ -0,0 +1,32 @@ +git-psuh(1) +============ + +NAME +---- +git-psuh - Delight users' typo with a shy horse + +SYNOPSIS +-------- +[verse] +'git psuh [...]' + +DESCRIPTION +----------- +A user-friendly command that delights users who accidentally type `git psuh` +instead of `git push`. This command provides a friendly message and some +useful information about the repository. + +OPTIONS +------- +None currently. + +EXAMPLES +-------- +---- +$ git psuh +Pony saying hello goes here. +---- + +GIT +---- +Part of the linkgit:git[1] suite \ No newline at end of file diff --git a/Makefile b/Makefile index e11340c1ae77ba..8a71b9701d83c1 100644 --- a/Makefile +++ b/Makefile @@ -1292,6 +1292,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 bff13e3069b4af..9a9a7e987b7120 100644 --- a/builtin.h +++ b/builtin.h @@ -101,15 +101,16 @@ extern const char git_more_info_string[]; * You should most likely use a default of 0 or 1. "Punt" (-1) could be useful * to be able to fall back to some historical compatibility name. */ + void setup_auto_pager(const char *cmd, int def); int is_builtin(const char *s); - /* * Builtins which do not use RUN_SETUP should never see * a prefix that is not empty; use this to protect downstream * code which is not prepared to call prefix_filename(), etc. */ + #define BUG_ON_NON_EMPTY_PREFIX(prefix) do { \ if ((prefix)) \ BUG("unexpected prefix in builtin: %s", (prefix)); \ @@ -202,6 +203,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix, struct r int cmd_patch_id(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_prune(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_prune_packed(int argc, const char **argv, const char *prefix, struct repository *repo); +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_pull(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_push(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_range_diff(int argc, const char **argv, const char *prefix, struct repository *repo); diff --git a/builtin/psuh.c b/builtin/psuh.c new file mode 100644 index 00000000000000..eefc1bc06bd89f --- /dev/null +++ b/builtin/psuh.c @@ -0,0 +1,59 @@ +#include "builtin.h" +#include "gettext.h" +#include "config.h" +#include "repository.h" +#include "wt-status.h" +#include "commit.h" +#include "pretty.h" +#include "strbuf.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, struct repository *repo) +{ + int i; + const char *cfg_name; + 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(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 : ""); + + repo_config(repo, git_die_config, NULL); + + if (repo_config_get_string_tmp(repo, "user.name", &cfg_name)) + printf(_("No name is found in config\n")); + else + printf(_("Your name: %s\n"), cfg_name); + + wt_status_prepare(repo, &status); + repo_config(repo, git_die_config, &status); + 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); + } + + strbuf_release(&commitline); + return 0; +} \ No newline at end of file diff --git a/command-list.txt b/command-list.txt index b7ade3ab9f3319..10be0f4b4dee39 100644 --- a/command-list.txt +++ b/command-list.txt @@ -151,6 +151,7 @@ git-pack-refs ancillarymanipulators git-patch-id purehelpers git-prune ancillarymanipulators complete git-prune-packed plumbingmanipulators +git-psuh mainporcelain info git-pull mainporcelain remote git-push mainporcelain remote git-quiltimport foreignscminterface diff --git a/git-psuh b/git-psuh new file mode 100755 index 00000000000000..e2d2aeb0b73cce Binary files /dev/null and b/git-psuh differ diff --git a/git.c b/git.c index 83eac0aeab75d6..0a14e62473058a 100644 --- a/git.c +++ b/git.c @@ -597,6 +597,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 }, diff --git a/meson.build b/meson.build index 5dd299b4962d84..6b0ca890cc87ee 100644 --- a/meson.build +++ b/meson.build @@ -629,6 +629,7 @@ builtin_sources = [ 'builtin/pack-objects.c', 'builtin/pack-refs.c', 'builtin/patch-id.c', + 'builtin/psuh.c', 'builtin/prune-packed.c', 'builtin/prune.c', 'builtin/pull.c', diff --git a/t/t9999-psuh-tutorial.sh b/t/t9999-psuh-tutorial.sh new file mode 100755 index 00000000000000..e4620e125da408 --- /dev/null +++ b/t/t9999-psuh-tutorial.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +test_description='git-psuh test +This test runs git-psuh and makes sure it does not crash or have other errors.' + +. ./test-lib.sh + +# This is the main test from the tutorial, ensuring the command +# runs and prints the expected output after setting the necessary config. +test_expect_success 'runs correctly with no args and good output' ' + git config user.name "Test User" && + git psuh >actual && + grep "Your name: Test User" actual +' + +# A simpler test just to ensure the command exits successfully. +test_expect_success 'git psuh does not crash' ' + git psuh +' + +test_done