From 865bbf7e0ef9548d271fecc0c2962c3e01229698 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 14 Nov 2017 12:35:03 -0800 Subject: [PATCH] mail.sh: tolerate running in a linked working tree The mail.sh script will not normally ever be run from within a linked working tree. However, such a feature could be useful for testing or perhaps some special kind of customization. Therefore support running from a current directory that is located within a linked working tree. Practically the only effect of this change is to show the correct project description when run from a linked working tree rather than "UNNAMED PROJECT" as nothing else is sensitive to running from a linked working tree. Signed-off-by: Kyle J. McKay --- taskd/mail.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/taskd/mail.sh b/taskd/mail.sh index 70cd2e1..7b12c4a 100755 --- a/taskd/mail.sh +++ b/taskd/mail.sh @@ -968,20 +968,28 @@ git_add_config core.abbrev=$habbr # Set GIT_DIR either from the working directory, or from the environment # variable. -GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +GIT_DIR="$(git rev-parse --git-dir 2>/dev/null)" || : if [ -z "$GIT_DIR" ]; then echol >&2 "fatal: mail.sh: GIT_DIR not set" exit 1 fi +# Get GIT_COMMON_DIR for Git >= 2.5.0 +GCD_DIR="$(cd "$GIT_DIR" && unset GIT_DIR && git rev-parse --git-common-dir 2>/dev/null)" || : +if [ -z "$GCD_DIR" ] || [ "$GCD_DIR" = "--git-common-dir" ]; then + # Must be pre-2.5.0 + GCD_DIR="$GIT_DIR" +else + # Might be relative to GIT_DIR so cd there first + GCD_DIR="$(cd "$GIT_DIR" && cd "$GCD_DIR" && pwd)" +fi projectdesc= -! [ -s "$GIT_DIR/description" ] || projectdesc=$(LC_ALL=C sed -ne '1p' "$GIT_DIR/description") +! [ -s "$GCD_DIR/description" ] || projectdesc="$(LC_ALL=C sed -ne '1p' "$GCD_DIR/description")" # Check if the description is unchanged from it's default, and shorten it to # a more manageable length if it is -if [ -z "$projectdesc" ] || LC_ALL=C expr "$projectdesc" : "Unnamed repository.*$" >/dev/null -then +case "$projectdesc" in ""|"Unnamed repository"*) projectdesc="UNNAMED PROJECT" -fi +esac # If --stdout is first argument send all output there instead of mailing if [ "$1" = "--stdout" ]; then -- 2.11.4.GIT