From: Stefan Beller <sbeller@google.com>
To: unlisted-recipients:; (no To-header on input)
Cc: git@vger.kernel.org, Stefan Beller <sbeller@google.com>
Subject: [PATCH] submodule operations: tighten pathspec errors
Date: Fri, 20 May 2016 18:21:29 -0700 [thread overview]
Message-ID: <1463793689-19496-1-git-send-email-sbeller@google.com> (raw)
when the pathspec did not match any path, error out.
Add the `--error-unmatch` switch to use the old behavior.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
This was taken from the Left Over Bits:
git submodule $cmd $pathspec may want to error out when the $pathspec does
not match any submodules. There must be an --unmatch-ok option to override
this safety, though. Cf. $gmane/289535
It's a first initial version with no tests (and probably conflicting with
some topics in flight), but I was curious how involved this issue actually is,
so I took a stab at implementing it.
I was debating if inside git-submodules.sh we want to pass around a variable
or instead export an environment variable GIT_SUBMODULE_UNMATCH, such that we
do not give it as an argument to the submodule--helper builtin.
(This version is developed on top of the sb/submodule-deinit-all)
Documentation/git-submodule.txt | 15 ++++++++++-----
builtin/submodule--helper.c | 19 +++++++++++--------
git-submodule.sh | 41 ++++++++++++++++++++++++++++++-----------
3 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index ad85183..ceacc02 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -11,16 +11,16 @@ SYNOPSIS
[verse]
'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
[--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
-'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
-'git submodule' [--quiet] init [--] [<path>...]
-'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)
-'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
+'git submodule' [--quiet] status [--error-unmatch] [--cached] [--recursive] [--] [<path>...]
+'git submodule' [--quiet] init [--error-unmatch] [--] [<path>...]
+'git submodule' [--quiet] deinit [--error-unmatch] [-f|--force] (--all|[--] <path>...)
+'git submodule' [--quiet] update [--error-unmatch] [--init] [--remote] [-N|--no-fetch]
[-f|--force] [--rebase|--merge] [--reference <repository>]
[--depth <depth>] [--recursive] [--] [<path>...]
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
[commit] [--] [<path>...]
'git submodule' [--quiet] foreach [--recursive] <command>
-'git submodule' [--quiet] sync [--recursive] [--] [<path>...]
+'git submodule' [--quiet] sync [--error-unmatch] [--recursive] [--] [<path>...]
DESCRIPTION
@@ -260,6 +260,11 @@ OPTIONS
The name of the branch is recorded as `submodule.<name>.branch` in
`.gitmodules` for `update --remote`.
+--error-unmatch::
+ If the pathspec included a specification that did not match,
+ the usual operation is to error out. This switch suppresses
+ error reporting and continues the operation.
+
-f::
--force::
This option is only valid for add, deinit and update commands.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 5295b72..91c49ec 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -19,7 +19,8 @@ struct module_list {
static int module_list_compute(int argc, const char **argv,
const char *prefix,
struct pathspec *pathspec,
- struct module_list *list)
+ struct module_list *list,
+ int unmatch)
{
int i, result = 0;
char *ps_matched = NULL;
@@ -36,10 +37,9 @@ static int module_list_compute(int argc, const char **argv,
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
-
- if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
- 0, ps_matched, 1) ||
- !S_ISGITLINK(ce->ce_mode))
+ if (!S_ISGITLINK(ce->ce_mode) ||
+ !match_pathspec(pathspec, ce->name, ce_namelen(ce),
+ 0, ps_matched, 1))
continue;
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
@@ -53,7 +53,9 @@ static int module_list_compute(int argc, const char **argv,
i++;
}
- if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
+ if (!unmatch &&
+ ps_matched &&
+ report_path_error(ps_matched, pathspec, prefix))
result = -1;
free(ps_matched);
@@ -63,11 +65,12 @@ static int module_list_compute(int argc, const char **argv,
static int module_list(int argc, const char **argv, const char *prefix)
{
- int i;
+ int i, unmatch = 0;
struct pathspec pathspec;
struct module_list list = MODULE_LIST_INIT;
struct option module_list_options[] = {
+ OPT_BOOL(0, "unmatch", &unmatch, N_("Do not report error if no matches are found")),
OPT_STRING(0, "prefix", &prefix,
N_("path"),
N_("alternative anchor for relative paths")),
@@ -82,7 +85,7 @@ static int module_list(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, module_list_options,
git_submodule_helper_usage, 0);
- if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
+ if (module_list_compute(argc, argv, prefix, &pathspec, &list, unmatch) < 0) {
printf("#unmatched\n");
return 1;
}
diff --git a/git-submodule.sh b/git-submodule.sh
index fb68f1f..f10e10a 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -6,13 +6,13 @@
dashless=$(basename "$0" | sed -e 's/-/ /')
USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
- or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
- or: $dashless [--quiet] init [--] [<path>...]
- or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
- or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] status [--error-unmatch] [--cached] [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] init [--error-unmatch] [--] [<path>...]
+ or: $dashless [--quiet] deinit [--error-unmatch] [-f|--force] (--all| [--] <path>...)
+ or: $dashless [--quiet] update [--error-unmatch] [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: $dashless [--quiet] foreach [--recursive] <command>
- or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
+ or: $dashless [--quiet] sync [--error-unmatch] [--recursive] [--] [<path>...]"
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. git-sh-setup
@@ -391,6 +391,9 @@ cmd_foreach()
--recursive)
recursive=1
;;
+ --error-unmatch)
+ unmatch=1
+ ;;
-*)
usage
;;
@@ -407,7 +410,7 @@ cmd_foreach()
# command in the subshell (and a recursive call to this function)
exec 3<&0
- git submodule--helper list --prefix "$wt_prefix"|
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix"|
while read mode sha1 stage sm_path
do
die_if_unmatched "$mode"
@@ -453,6 +456,9 @@ cmd_init()
-q|--quiet)
GIT_QUIET=1
;;
+ --error-unmatch)
+ unmatch=1
+ ;;
--)
shift
break
@@ -467,7 +473,7 @@ cmd_init()
shift
done
- git submodule--helper list --prefix "$wt_prefix" "$@" |
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix" "$@" |
while read mode sha1 stage sm_path
do
die_if_unmatched "$mode"
@@ -534,6 +540,9 @@ cmd_deinit()
--all)
deinit_all=t
;;
+ --error-unmatch)
+ unmatch=1
+ ;;
--)
shift
break
@@ -558,7 +567,7 @@ cmd_deinit()
die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
fi
- git submodule--helper list --prefix "$wt_prefix" "$@" |
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix" "$@" |
while read mode sha1 stage sm_path
do
die_if_unmatched "$mode"
@@ -661,6 +670,9 @@ cmd_update()
--recursive)
recursive=1
;;
+ --error-unmatch)
+ unmatch=1
+ ;;
--checkout)
update="checkout"
;;
@@ -692,7 +704,7 @@ cmd_update()
fi
cloned_modules=
- git submodule--helper list --prefix "$wt_prefix" "$@" | {
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix" "$@" | {
err=
while read mode sha1 stage sm_path
do
@@ -1115,6 +1127,9 @@ cmd_status()
--recursive)
recursive=1
;;
+ --error-unmatch)
+ unmatch=1
+ ;;
--)
shift
break
@@ -1129,7 +1144,7 @@ cmd_status()
shift
done
- git submodule--helper list --prefix "$wt_prefix" "$@" |
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix" "$@" |
while read mode sha1 stage sm_path
do
die_if_unmatched "$mode"
@@ -1193,6 +1208,10 @@ cmd_sync()
recursive=1
shift
;;
+ --error-unmatch)
+ unmatch=1
+ shift
+ ;;
--)
shift
break
@@ -1206,7 +1225,7 @@ cmd_sync()
esac
done
cd_to_toplevel
- git submodule--helper list --prefix "$wt_prefix" "$@" |
+ git submodule--helper list ${unmatch:+--unmatch} --prefix "$wt_prefix" "$@" |
while read mode sha1 stage sm_path
do
die_if_unmatched "$mode"
--
2.8.0.2.gaa9b48a.dirty
next reply other threads:[~2016-05-21 1:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-21 1:21 Stefan Beller [this message]
2016-05-26 20:00 ` [PATCH] submodule operations: tighten pathspec errors Junio C Hamano
2016-06-01 20:55 ` Stefan Beller
2016-06-01 21:14 ` Junio C Hamano
2016-06-01 21:20 ` Junio C Hamano
2016-06-06 19:31 ` Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463793689-19496-1-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.