diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-04-21 15:35:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-21 15:35:05 -0700 |
commit | b64894c2063e5875bfd95b537eafcb3e1abf46ff (patch) | |
tree | 989d1d734418b366f23738b228b96dcd6ec1acbd /builtin/branch.c | |
parent | 9e0d1aa495bd26f4688b915ac5c3cb656c9f7174 (diff) | |
parent | aabfdc9514a51d8d9a2f3afbc29e5044ccf7191b (diff) |
Merge branch 'ow/ref-filter-omit-empty'
"git branch --format=..." and "git format-patch --format=..."
learns "--omit-empty" to hide refs that whose formatting result
becomes an empty string from the output.
* ow/ref-filter-omit-empty:
branch, for-each-ref, tag: add option to omit empty lines
Diffstat (limited to 'builtin/branch.c')
-rw-r--r-- | builtin/branch.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 68964eef2d..bb7e1ac206 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -44,6 +44,7 @@ static const char *head; static struct object_id head_oid; static int recurse_submodules = 0; static int submodule_propagate_branches = 0; +static int omit_empty = 0; static int branch_use_color = -1; static char branch_colors[][COLOR_MAXLEN] = { @@ -483,7 +484,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin string_list_append(output, out.buf); } else { fwrite(out.buf, 1, out.len, stdout); - putchar('\n'); + if (out.len || !omit_empty) + putchar('\n'); } } @@ -692,6 +694,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2), OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1), OPT_BIT('M', NULL, &rename, N_("move/rename a branch, even if target exists"), 2), + OPT_BOOL(0, "omit-empty", &omit_empty, + N_("do not output a newline after empty formatted refs")), OPT_BIT('c', "copy", ©, N_("copy a branch and its reflog"), 1), OPT_BIT('C', NULL, ©, N_("copy a branch, even if target exists"), 2), OPT_BOOL('l', "list", &list, N_("list branch names")), |