----
$ git clone https://github.com/git/git git
+$ cd git
----
[[identify-problem]]
Check it out! You've got a command! Nice work! Let's commit this.
+`git status` reveals modified `Makefile`, `builtin.h`, and `git.c` as well as
+untracked `builtin/psuh.c` and `git-psuh`. First, let's take care of the binary,
+which should be ignored. Open `.gitignore` in your editor, find `/git-push`, and
+add an entry for your new command in alphabetical order:
+
+----
+...
+/git-prune-packed
+/git-psuh
+/git-pull
+/git-push
+/git-quiltimport
+/git-range-diff
+...
----
-$ git add Makefile builtin.h builtin/psuh.c git.c
+
+Checking `git status` again should show that `git-psuh` has been removed from
+the untracked list and `.gitignore` has been added to the modified list. Now we
+can stage and commit:
+
+----
+$ git add Makefile builtin.h builtin/psuh.c git.c .gitignore
$ git commit -s
----
It's probably useful to do at least something besides printing out a string.
Let's start by having a look at everything we get.
-Modify your `cmd_psuh` implementation to dump the args you're passed:
+Modify your `cmd_psuh` implementation to dump the args you're passed, keeping
+existing `printf()` calls in place:
----
int i;
...
- git_config(git_default_config, NULL)
+ 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
Let's commit this as well.
----
+$ git add builtin/psuh.c
$ git commit -sm "psuh: print the current branch"
----
about. Neat! Let's commit that as well.
----
+$ git add builtin/psuh.c
$ git commit -sm "psuh: display the top of origin/master"
----
SYNOPSIS
--------
[verse]
-'git-psuh'
+'git-psuh [<arg>...]'
DESCRIPTION
-----------
------
...
-
GIT
---
Part of the linkgit:git[1] suite
tool for pulling out options you need to be able to handle, and it takes a
usage string.
-In order to use it, we'll need to prepare a NULL-terminated usage string and a
-`builtin_psuh_options` array. Add a line to `#include "parse-options.h"`.
+In order to use it, we'll need to prepare a NULL-terminated array of usage
+strings and a `builtin_psuh_options` array.
+
+Add a line to `#include "parse-options.h"`.
-At global scope, add your usage:
+At global scope, add your array of usage strings:
----
static const char * const psuh_usage[] = {
- N_("git psuh"),
+ N_("git psuh [<arg>...]"),
NULL,
};
----