Skip to content
Closed
32 changes: 32 additions & 0 deletions Documentation/git-psuh.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
git-psuh(1)
============

NAME
----
git-psuh - Delight users' typo with a shy horse

SYNOPSIS
--------
[verse]
'git psuh [<arg>...]'

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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
Expand Down Expand Up @@ -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);
Expand Down
59 changes: 59 additions & 0 deletions builtin/psuh.c
Original file line number Diff line number Diff line change
@@ -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 [<arg>...]"),
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<top-level>%s%s\n"),
prefix ? "/" : "", prefix ? prefix : "");

repo_config(repo, git_die_config, NULL);

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

builtin/psuh.c:40:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

builtin/psuh.c:40:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

builtin/psuh.c:40:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

builtin/psuh.c:40:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

builtin/psuh.c:40:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

builtin/psuh.c:40:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 40 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / win build

builtin/psuh.c:40:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Wincompatible-pointer-types]

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);

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

builtin/psuh.c:48:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

builtin/psuh.c:48:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

builtin/psuh.c:48:23: passing argument 2 of ‘repo_config’ from incompatible pointer type [-Wincompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

builtin/psuh.c:48:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Werror=incompatible-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

builtin/psuh.c:48:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

builtin/psuh.c:48:23: incompatible function pointer types passing 'void (struct repository *, const char *, const char *, ...) __attribute__((noreturn))' to parameter of type 'config_fn_t' (aka 'int (*)(const char *, const char *, const struct config_context *, void *)') [-Wincompatible-function-pointer-types]

Check failure on line 48 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / win build

builtin/psuh.c:48:23: passing argument 2 of 'repo_config' from incompatible pointer type [-Wincompatible-pointer-types]
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;
}

Check failure on line 59 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

builtin/psuh.c:59:2: no newline at end of file [-Werror,-Wnewline-eof]

Check failure on line 59 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

builtin/psuh.c:59:2: no newline at end of file [-Werror,-Wnewline-eof]

Check failure on line 59 in builtin/psuh.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

builtin/psuh.c:59:2: no newline at end of file [-Werror,-Wnewline-eof]
1 change: 1 addition & 0 deletions command-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added git-psuh
Binary file not shown.
1 change: 1 addition & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions t/t9999-psuh-tutorial.sh
Original file line number Diff line number Diff line change
@@ -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
Loading