summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2018-08-18 16:20:46 -0400
committerPhilip Chimento <philip.chimento@gmail.com>2018-10-08 15:59:31 -0700
commita3e117621a9ddf3d9c3c342b03470dcccf09fb69 (patch)
tree2399bf1615b72c833d1d9693e70d0dd77f867a2c
parentcf56080b6d21100bec9b83c1bb677ef5f611efc5 (diff)
downloadgjs-a3e117621a9ddf3d9c3c342b03470dcccf09fb69.tar.gz
tools: Update clang-format scripts
A few bugs have been fixed upstream.
-rwxr-xr-xtools/apply-format6
-rwxr-xr-xtools/git-pre-commit-format27
2 files changed, 28 insertions, 5 deletions
diff --git a/tools/apply-format b/tools/apply-format
index 9ea3ead5..a601fe58 100755
--- a/tools/apply-format
+++ b/tools/apply-format
@@ -162,7 +162,7 @@ if [ ${#positionals[@]} -gt 0 ]; then
fi
[ -n "$style" ] || \
- error_exit "If you use --style you need to speficy a valid style."
+ error_exit "If you use --style you need to specify a valid style."
#######################################
# Detection of clang-format & friends #
@@ -181,7 +181,7 @@ if [ -z "$format" ]; then
$'On Ubuntu/Debian this is available in the clang-format package or, in\n' \
$'older distro versions, clang-format-VERSION.\n' \
$'On Fedora it\'s available in the clang package.\n' \
- $'You can also speficy your own path for clang-format by setting the\n' \
+ $'You can also specify your own path for clang-format by setting the\n' \
$'$CLANG_FORMAT environment variable.'
fi
@@ -249,7 +249,7 @@ if [ "$whole_file" = false ]; then
$'at https://github.com/barisione/clang-format-hooks/issues with details about\n' \
$'your operating system and setup.\n' \
$'\n' \
- $'You can also speficy your own path for clang-format-diff by setting the\n' \
+ $'You can also specify your own path for clang-format-diff by setting the\n' \
$'$CLANG_FORMAT_DIFF environment variable, for instance:\n' \
$'\n' \
$' CLANG_FORMAT_DIFF="python /.../clang-format-diff.py" \\\n' \
diff --git a/tools/git-pre-commit-format b/tools/git-pre-commit-format
index 36495093..90fcc334 100755
--- a/tools/git-pre-commit-format
+++ b/tools/git-pre-commit-format
@@ -80,6 +80,7 @@ function rel_realpath() {
# Find the top-level git directory (taking into account we could be in a submodule).
declare git_test_dir=.
declare top_dir
+
while true; do
top_dir=$(cd "$git_test_dir" && git rev-parse --show-toplevel) || \
error_exit "You need to be in the git repository to run this script."
@@ -90,8 +91,30 @@ while true; do
if [ -d "$top_dir/.git" ]; then
# We are done! top_dir is the root git directory.
break
- else
- # We are in a submodule if .git is a file!
+ elif [ -f "$top_dir/.git" ]; then
+ # We are in a submodule or git work-tree if .git is a file!
+ if [ -z "$(git rev-parse --show-superproject-working-tree)" ]; then
+ # The --show-superproject-working-tree option is available and we
+ # are in a work tree.
+ gitdir=$(<"$top_dir/.git")
+ gitdir=${gitdir#gitdir: }
+ topdir_basename=${gitdir##*/}
+ git_test_dir=${gitdir%/worktrees/$topdir_basename}
+ break
+ fi
+ # If show-superproject-working-tree returns non-empty string, either:
+ #
+ # 1) --show-superproject-working-tree is not defined for this version of git
+ #
+ # 2) --show-superproject-working-tree is defined and we are in a submodule
+ #
+ # In the first case we will assume it is not a work tree because people
+ # using that advanced technology will be using a recent version of git.
+ #
+ # In second case, we could use the value returned by
+ # --show-superproject-working-tree directly but we do not here because
+ # that would require extra work.
+ #
git_test_dir="$git_test_dir/.."
fi
done