Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error message when loading from a non-git directory #1927

Open
rmkaplan opened this issue Dec 20, 2024 · 4 comments
Open

fatal error message when loading from a non-git directory #1927

rmkaplan opened this issue Dec 20, 2024 · 4 comments
Assignees

Comments

@rmkaplan
Copy link
Contributor

I routinely run the loadup script in my working directory, which is not a git clone.

I noticed that at almost every step it prints out
fatal: not a git repository (or any of the parent directories): .git

It's true that it isn't a repository, but did something really go wrong? Or it's just an error message that should be suppressed or phrased in a different way.

Is there something wrong with building in a non-repository?

This is on Mac 14.6.1 Sonoma

@nbriggs
Copy link
Contributor

nbriggs commented Dec 21, 2024

There's nothing actually wrong -- it's just that the setup script tries to figure out the git commit id of what you're building from and in the non-repository case git itself reports "fatal: not a git repository (or any of the parent directories)". It does that to standard error, so we could add a 2>/dev/null to the git commands in there, which would just make it silent. It's too bad there's no --silent or --quiet option.

@rmkaplan
Copy link
Contributor Author

rmkaplan commented Dec 21, 2024 via email

@nbriggs
Copy link
Contributor

nbriggs commented Dec 21, 2024

I'd suggest this patch to medley/scripts/loadup-setup.sh

diff --git a/scripts/loadup-setup.sh b/scripts/loadup-setup.sh
index be7305b2..47825408 100644
--- a/scripts/loadup-setup.sh
+++ b/scripts/loadup-setup.sh
@@ -50,15 +50,9 @@ then
   fi
 fi
 
-HAS_GIT= [ -f $(which git) ] && [ -x $(which git) ]
-export HAS_GIT
-
 git_commit_ID () {
-  if ${HAS_GIT};
-  then
-    # This does NOT indicate if there are any modified files!
-    COMMIT_ID=$(git -C "$1" rev-parse --short HEAD)
-  fi
+# This does NOT indicate if there are any modified files!
+COMMIT_ID=$(git -C "$1" rev-parse --short HEAD 2>/dev/null)
 }
 
 git_commit_ID "${LOADUP_SOURCEDIR}"

there is no other use of HAS_GIT in any of the scripts, the existing code doesn't appear to work cleanly if git is not installed, and if git exists but the script is run in a non-repo, it prints git's "fatal: ..." error message.

@nbriggs
Copy link
Contributor

nbriggs commented Dec 22, 2024

For reference - this is the script fragment I use for the Maiko git revision to determine if git is installed and the command is being executed within a git repository:

if command -v "git" >/dev/null 2>&1; then
    MAIKO_REV="$(git status --porcelain)"
    if [ $? == 0 ]; then
        if [ ! -z "$(git status --porcelain)" ]; then
            MAIKO_REV="$(git rev-parse --short HEAD)-dirty"
        else
            MAIKO_REV="$(git rev-parse --short HEAD)"
        fi
    else
        MAIKO_REV="none"
    fi
else
    MAIKO_REV = "none"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants