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

Unable to find a git directory and/or git is not installed #76

Closed
aforsythe opened this issue Feb 1, 2022 · 11 comments
Closed

Unable to find a git directory and/or git is not installed #76

aforsythe opened this issue Feb 1, 2022 · 11 comments

Comments

@aforsythe
Copy link

Pretty sure this is user error, but I receiving the following error.

ERROR    -  [git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed. To ignore this error, set option  'fallback_to_build_date: true'

Problem is, git is installed :

$ git status

On branch amf-userguide
Your branch is up to date with 'aforsythe/amf-userguide'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   mkdocs.yml

no changes added to commit (use "git add" and/or "git commit -a")

Had this running fine on another test instance, but can't figure out what's going wrong here. Any suggestions would be greatly appreciated.

@timvink
Copy link
Owner

timvink commented Feb 1, 2022

Going to need a bit more info.

You cloned a repo, cd-ed into it, and running mkdocs serve gives you this error?

What OS are you on? Which version of python? Running the latest mkdocs package and of this package?

@timvink
Copy link
Owner

timvink commented Feb 1, 2022

Also, is there a larger traceback you can paste ?

@aforsythe
Copy link
Author

Thanks ...

Here's the full traceback

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 177, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 54, in serve
    config = builder()
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 49, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 257, in build
    config = config['plugins'].run_event('config', config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 102, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/plugin.py", line 65, in on_config
    self.last_site_revision_timestamp = self.util.get_git_commit_timestamp(
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 135, in get_git_commit_timestamp
    raise err
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 106, in get_git_commit_timestamp
    git = self._get_repo(realpath)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 40, in _get_repo
    self.repo_cache[path] = Repo(path, search_parent_directories=True).git
  File "/usr/local/lib/python3.9/site-packages/git/repo/base.py", line 224, in __init__
    self.working_dir: Optional[PathLike] = self._working_tree_dir or self.common_dir
  File "/usr/local/lib/python3.9/site-packages/git/repo/base.py", line 307, in common_dir
    raise InvalidGitRepositoryError()
git.exc.InvalidGitRepositoryError

Running mkdocs-material using the squidfunk/mkdocs-material docker image.
Using plugins so running with the following Dockerfile

FROM squidfunk/mkdocs-material

WORKDIR /tmp
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
WORKDIR /docs

requirements.txt is

mkdocs-material
mkdocs-enumerate-headings-plugin
mkdocs-git-revision-date-localized-plugin
mkdocs-mermaid2-plugin
mkdocs-techdocs-core

I think I might know what's going on here but don't know how to address ... The directory in which I'm currently docker run --rm -it -p 8000:8000 -v ${PWD}:/docs myImage isn't the root of the git repository, so it looks like inside the container there's no knowledge of the .git hidden folder which exists one level up.

@oliversalzburg
Copy link
Contributor

@aforsythe If the .git directory is not mounted into the container, that's likely a problem. Why not mount the parent folder (likely your entire repo) into /docs instead? That is what we do anyway.

@timvink
Copy link
Owner

timvink commented Feb 2, 2022

Indeed that seems to be the problem. The official mkdocs-material docker image states:

Mount the folder where your mkdocs.yml resides as a volume into /docs:
Start development server on http://localhost:8000
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material

Is mkdocs.yml in the root of your repository, same as where your .git folder is? Alternatively, is there a .dockerignore file in your project that ignores the .git folder?

@aforsythe
Copy link
Author

No .dockerignore ...

The Dockerfile and the mkdocs.yml are in the subdirectory of the repo. That's what is getting mounted as a docker volume, so the container isn't seeing the .git directory that's one level up. I tried moving the Dockerfile up, mounting the top level directory, but then mkdocs doesn't build with the squidfunk/mkdocs-material docker image because it assumes the mkdocs.yml is in the directory that gets mounted to /docs in the container.

Sorry this obviously isn't an issue with your plugin, but if you've got thoughts on how to manage the issue in an elegant fashion, I'd love your input. I can brute force it by copying the contents of the mkdocs-material Dockerfile into my Dockerfile and modifying the working directory, but I'm hoping there's a more elegant solution.

@oliversalzburg
Copy link
Contributor

@aforsythe Not sure if this can help, but I came across https://github.com/backstage/mkdocs-monorepo-plugin while looking through https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins. Maybe this, or another similar plugin, can support your use case as well.

@aforsythe
Copy link
Author

aforsythe commented Feb 3, 2022

Thanks so much for the help. I did find a work around. I moved the Dockerfile and mkdocs.yml up to the root of the git repo. Then I attached the docker volume to the git repo root also, but changed the mkdocs.yml to reflect the new docs_dir structure and the location of the theme with custom_dir. Hoping there's no unintended side effects but all seems to be working now.

@timvink
Copy link
Owner

timvink commented Feb 3, 2022

@squidfunk any possibility we can improve the mkdocs-material docker image for better compatibility / easier setup with plugins that use git ? Reading the thread above it seems we might be able to make things easier :)

@aforsythe
Copy link
Author

Certainly any way to make it a little clearer how to deal with this sort of situation, would be appreciated. I'm coming to mkdocs and mkdocs-material pretty green, so there's some stuff that was pretty obvious that I just messed up along the way. This felt like it required a bit of digging to get right.

@squidfunk
Copy link
Sponsor Collaborator

@timvink the getting started guide assumes that mkdocs.yml and the .git folder are on the same level, yes. If you deviate from that path, i.e. mount a subfolder, YMMV. I don't want to make the getting started guide any more complicated, but we can certainly add a note to the setup page of your plugin. If you feel that this is a good idea, a PR is appreciated.

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

4 participants