Skip to content

Commit

Permalink
Merge branch 'jk/submodule-subdirectory-ok'
Browse files Browse the repository at this point in the history
Allow various subcommands of "git submodule" to be run not from the
top of the working tree of the superproject.

* jk/submodule-subdirectory-ok:
  submodule: drop the top-level requirement
  rev-parse: add --prefix option
  submodule: show full path in error message
  t7403: add missing && chaining
  t7403: modernize style
  t7401: make indentation consistent
  • Loading branch information
Junio C Hamano committed Jun 30, 2013
2 parents 3c36e8a + 091a6eb commit d9857bf
Show file tree
Hide file tree
Showing 9 changed files with 673 additions and 213 deletions.
16 changes: 16 additions & 0 deletions Documentation/git-rev-parse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ OPTIONS
If there is no parameter given by the user, use `<arg>`
instead.

--prefix <arg>::
Behave as if 'git rev-parse' was invoked from the `<arg>`
subdirectory of the working tree. Any relative filenames are
resolved as if they are prefixed by `<arg>` and will be printed
in that form.
+
This can be used to convert arguments to a command run in a subdirectory
so that they can still be used after moving to the top-level of the
repository. For example:
+
----
prefix=$(git rev-parse --show-prefix)
cd "$(git rev-parse --show-toplevel)"
eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")"
----

--verify::
Verify that exactly one parameter is provided, and that it
can be turned into a raw 20-byte SHA-1 that can be used to
Expand Down
24 changes: 19 additions & 5 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,17 @@ static void show_datestring(const char *flag, const char *datestr)
show(buffer);
}

static int show_file(const char *arg)
static int show_file(const char *arg, int output_prefix)
{
show_default();
if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
show(arg);
if (output_prefix) {
const char *prefix = startup_info->prefix;
show(prefix_filename(prefix,
prefix ? strlen(prefix) : 0,
arg));
} else
show(arg);
return 1;
}
return 0;
Expand Down Expand Up @@ -470,6 +476,7 @@ N_("git rev-parse --parseopt [options] -- [<args>...]\n"
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
int output_prefix = 0;
unsigned char sha1[20];
const char *name = NULL;

Expand Down Expand Up @@ -503,7 +510,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
const char *arg = argv[i];

if (as_is) {
if (show_file(arg) && as_is < 2)
if (show_file(arg, output_prefix) && as_is < 2)
verify_filename(prefix, arg, 0);
continue;
}
Expand All @@ -527,14 +534,21 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
as_is = 2;
/* Pass on the "--" if we show anything but files.. */
if (filter & (DO_FLAGS | DO_REVS))
show_file(arg);
show_file(arg, 0);
continue;
}
if (!strcmp(arg, "--default")) {
def = argv[i+1];
i++;
continue;
}
if (!strcmp(arg, "--prefix")) {
prefix = argv[i+1];
startup_info->prefix = prefix;
output_prefix = 1;
i++;
continue;
}
if (!strcmp(arg, "--revs-only")) {
filter &= ~DO_NOREV;
continue;
Expand Down Expand Up @@ -754,7 +768,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
if (verify)
die_no_single_rev(quiet);
as_is = 1;
if (!show_file(arg))
if (!show_file(arg, output_prefix))
continue;
verify_filename(prefix, arg, 1);
}
Expand Down
Loading

0 comments on commit d9857bf

Please sign in to comment.