Skip to content

Commit 2cbdd9c

Browse files
committed
config-batch: basic boilerplate of new builtin
Later changes will document, implement, and test this new builtin. For now, this serves as the latest example of the minimum boilerplate to introduce a new builtin. Recently, we updated the comment in builtin.h about how to create a new builtin, but failed to mention the required change to meson.build for some CI builds to pass. Fix that oversight. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent b5c409c commit 2cbdd9c

File tree

10 files changed

+77
-0
lines changed

10 files changed

+77
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
/git-commit-graph
4545
/git-commit-tree
4646
/git-config
47+
/git-config-batch
4748
/git-count-objects
4849
/git-credential
4950
/git-credential-cache
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
git-config-batch(1)
2+
===================
3+
4+
NAME
5+
----
6+
git-config-batch - Get and set options using machine-parseable interface
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
'git config-batch' <options>
13+
14+
DESCRIPTION
15+
-----------
16+
TODO
17+
18+
SEE ALSO
19+
--------
20+
linkgit:git-config[1]
21+
22+
GIT
23+
---
24+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ BUILTIN_OBJS += builtin/commit-graph.o
13901390
BUILTIN_OBJS += builtin/commit-tree.o
13911391
BUILTIN_OBJS += builtin/commit.o
13921392
BUILTIN_OBJS += builtin/config.o
1393+
BUILTIN_OBJS += builtin/config-batch.o
13931394
BUILTIN_OBJS += builtin/count-objects.o
13941395
BUILTIN_OBJS += builtin/credential-cache--daemon.o
13951396
BUILTIN_OBJS += builtin/credential-cache.o

builtin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@
6868
*
6969
* . Add `builtin/foo.o` to `BUILTIN_OBJS` in `Makefile`.
7070
*
71+
* . Add 'builtin/foo.c' to the 'builtin_sources' array in 'meson.build'.
72+
*
7173
* Additionally, if `foo` is a new command, there are 4 more things to do:
7274
*
7375
* . Add tests to `t/` directory.
7476
*
77+
* . Add the test script to 'integration_tests' in 't/meson.build'.
78+
*
7579
* . Write documentation in `Documentation/git-foo.adoc`.
7680
*
7781
* . Add an entry for `git-foo` to `command-list.txt`.
@@ -167,6 +171,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix, struct repositor
167171
int cmd_commit_graph(int argc, const char **argv, const char *prefix, struct repository *repo);
168172
int cmd_commit_tree(int argc, const char **argv, const char *prefix, struct repository *repo);
169173
int cmd_config(int argc, const char **argv, const char *prefix, struct repository *repo);
174+
int cmd_config_batch(int argc, const char **argv, const char *prefix, struct repository *repo);
170175
int cmd_count_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
171176
int cmd_credential(int argc, const char **argv, const char *prefix, struct repository *repo);
172177
int cmd_credential_cache(int argc, const char **argv, const char *prefix, struct repository *repo);

builtin/config-batch.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
#include "builtin.h"
3+
#include "config.h"
4+
#include "environment.h"
5+
#include "parse-options.h"
6+
7+
static const char *const builtin_config_batch_usage[] = {
8+
N_("git config-batch <options>"),
9+
NULL
10+
};
11+
12+
int cmd_config_batch(int argc,
13+
const char **argv,
14+
const char *prefix,
15+
struct repository *repo)
16+
{
17+
struct option options[] = {
18+
OPT_END(),
19+
};
20+
21+
show_usage_with_options_if_asked(argc, argv,
22+
builtin_config_batch_usage, options);
23+
24+
argc = parse_options(argc, argv, prefix, options, builtin_config_batch_usage,
25+
0);
26+
27+
repo_config(repo, git_default_config, NULL);
28+
29+
return 0;
30+
}

command-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ git-commit mainporcelain history
8383
git-commit-graph plumbingmanipulators
8484
git-commit-tree plumbingmanipulators
8585
git-config ancillarymanipulators complete
86+
git-config-batch plumbinginterrogators
8687
git-count-objects ancillaryinterrogators
8788
git-credential purehelpers
8889
git-credential-cache purehelpers

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ static struct cmd_struct commands[] = {
557557
{ "commit-graph", cmd_commit_graph, RUN_SETUP },
558558
{ "commit-tree", cmd_commit_tree, RUN_SETUP },
559559
{ "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
560+
{ "config-batch", cmd_config_batch, RUN_SETUP_GENTLY },
560561
{ "count-objects", cmd_count_objects, RUN_SETUP },
561562
{ "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },
562563
{ "credential-cache", cmd_credential_cache },

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ builtin_sources = [
582582
'builtin/commit-tree.c',
583583
'builtin/commit.c',
584584
'builtin/config.c',
585+
'builtin/config-batch.c',
585586
'builtin/count-objects.c',
586587
'builtin/credential-cache--daemon.c',
587588
'builtin/credential-cache.c',

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ integration_tests = [
186186
't1309-early-config.sh',
187187
't1310-config-default.sh',
188188
't1311-config-optional.sh',
189+
't1312-config-batch.sh',
189190
't1350-config-hooks-path.sh',
190191
't1400-update-ref.sh',
191192
't1401-symbolic-ref.sh',

t/t1312-config-batch.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
test_description='Test git config-batch'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'help text' '
8+
test_must_fail git config-batch -h >out &&
9+
grep usage out
10+
'
11+
12+
test_done

0 commit comments

Comments
 (0)