Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH]: psuh subcommand implementation #1807

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
/git-patch-id
/git-prune
/git-prune-packed
/git-psuh
/git-pull
/git-push
/git-quiltimport
Expand Down
32 changes: 32 additions & 0 deletions Documentation/git-psuh.txt
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
-----------
Prints the commandline variables,
gets the user's current working directory and prints it,
the user's name in the git config file, the current branch
and also the commitline.


OPTIONS[[OPTIONS]]
------------------
...

OUTPUT
------
...

GIT
---
Part of the git[1] suite
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,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
1 change: 1 addition & 0 deletions builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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
66 changes: 66 additions & 0 deletions builtin/psuh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "builtin.h"
#include "config.h"
#include "gettext.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) {
const char *cfg_name;
struct wt_status status;
struct commit *c = NULL;
struct strbuf commitline = STRBUF_INIT;
int i;

struct option options[] = {
OPT_END()
};

argc = parse_options(argc, argv, prefix, options, psuh_usage, 0);
printf(_("Pony saying hello goes here.\n"));
printf("%d\n", repo->different_commondir);
printf(_("%s\n"), prefix);

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

// git config implementation
git_config(git_default_config, NULL);
if(git_config_get_string_tmp("user.name", &cfg_name) > 0)
printf(_("No name is found in config\n"));
else
printf(_("Your name: %s\n"), cfg_name);

// getting current branch from status struct
wt_status_prepare(the_repository, &status);
git_config(git_default_config, &status);
printf(_("Your current branch: %s\n"), status.branch);

// get info from a commit
c = lookup_commit_reference_by_name("psuh");

if (c != NULL) {
pp_commit_easy(CMIT_FMT_ONELINE, c, &commitline);
printf(_("Current commit: %s"), commitline.buf);
}
return 0;

}
1 change: 1 addition & 0 deletions command-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,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
1 change: 1 addition & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,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
13 changes: 13 additions & 0 deletions t/t9999-psuh-tutorial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

test_description='git-psuh test

This test runs git-psuh and makes sure it does not crash'

. ./test-lib.sh

test_expect_success "runs corrrectly with no args and good output" '
git psuh >actual &&
grep Pony actual
'
test_done
Loading