Merge branch 'sd/cd-p-show-toplevel'
* sd/cd-p-show-toplevel: Use $(git rev-parse --show-toplevel) in cd_to_toplevel(). Add 'git rev-parse --show-toplevel' option.
This commit is contained in:
@ -112,6 +112,9 @@ OPTIONS
|
|||||||
--remotes::
|
--remotes::
|
||||||
Show tag refs found in `$GIT_DIR/refs/remotes`.
|
Show tag refs found in `$GIT_DIR/refs/remotes`.
|
||||||
|
|
||||||
|
--show-toplevel::
|
||||||
|
Show the absolute path of the top-level directory.
|
||||||
|
|
||||||
--show-prefix::
|
--show-prefix::
|
||||||
When the command is invoked from a subdirectory, show the
|
When the command is invoked from a subdirectory, show the
|
||||||
path of the current directory relative to the top-level
|
path of the current directory relative to the top-level
|
||||||
|
@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
|||||||
for_each_remote_ref(show_reference, NULL);
|
for_each_remote_ref(show_reference, NULL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(arg, "--show-toplevel")) {
|
||||||
|
const char *work_tree = get_git_work_tree();
|
||||||
|
if (work_tree)
|
||||||
|
puts(work_tree);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!strcmp(arg, "--show-prefix")) {
|
if (!strcmp(arg, "--show-prefix")) {
|
||||||
if (prefix)
|
if (prefix)
|
||||||
puts(prefix);
|
puts(prefix);
|
||||||
|
@ -120,20 +120,11 @@ is_bare_repository () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cd_to_toplevel () {
|
cd_to_toplevel () {
|
||||||
cdup=$(git rev-parse --show-cdup)
|
cdup=$(git rev-parse --show-toplevel) &&
|
||||||
if test ! -z "$cdup"
|
cd "$cdup" || {
|
||||||
then
|
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
|
||||||
# The "-P" option says to follow "physical" directory
|
exit 1
|
||||||
# structure instead of following symbolic links. When cdup is
|
}
|
||||||
# "../", this means following the ".." entry in the current
|
|
||||||
# directory instead textually removing a symlink path element
|
|
||||||
# from the PWD shell variable. The "-P" behavior is more
|
|
||||||
# consistent with the C-style chdir used by most of Git.
|
|
||||||
cd -P "$cdup" || {
|
|
||||||
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_work_tree () {
|
require_work_tree () {
|
||||||
|
Reference in New Issue
Block a user