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

Add --safe-directory flag #86

Closed
sgriffith3 opened this issue Oct 3, 2022 · 2 comments
Closed

Add --safe-directory flag #86

sgriffith3 opened this issue Oct 3, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@sgriffith3
Copy link

Is your feature request related to a problem? Please describe.
My team has been struggling to get the newest release (0.3.12) to work inside of a Jenkins environment, that then launches the convco container with docker.

Running this command:

docker run -v "$PWD:/tmp" --workdir /tmp --rm convco

We have been seeing the error:

Error: Git(Error { code: -3, klass: 7, message: "config value 'safe.directory' was not found" })

While this would regularly be overcome easily with the command git config --add safe.directory *, this is unfortunately not an option for the docker container as far as we have figured out.

Describe the solution you'd like
I would like an easy way to add a safe-directory. I believe this could be achieved with convco updating the configuration of git, and therefore suggest adding an optional flag that would temporarily add a specified safe directory.

Describe alternatives you've considered
Our workaround to this was to create a gitconfig file, and mount that as a volume.

# gitconfig
[safe]
  directory=/tmp

Working command:
docker run --rm -v "$PWD:/tmp" -v "$PWD/gitconfig:/etc/gitconfig" -w /tmp convco version

Additional context
If this is not possible for the time being, a note in the README indicating this workaround would be nice.

@sgriffith3 sgriffith3 added the enhancement New feature or request label Oct 3, 2022
@hdevalke
Copy link
Collaborator

hdevalke commented Oct 3, 2022

I had to lookup what this safe directory is doing:

https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory
These config entries specify Git-tracked directories that are considered safe even if they are owned by someone other than the current user.

is it possible the directory /tmp is not owned by the user running docker (i guess root is running in your example, but the pwd is owned by the jenkins user? docker run -u "$(id -u):$(id -g)" -v "$PWD:/tmp" --workdir /tmp --rm convco could probably solve your issue as well.

The issue with * is probably related to libgit2/libgit2#6391.

hdevalke added a commit that referenced this issue Oct 4, 2022
If the git repo can't be opened because of the `safe.directory` config a hint will be printed:

> Could not open the git repository.
> If run from docker set the right user id and group id.
> E.g. `docker run -u \"$(id -u):$(id -g)\" -v \"$PWD:/tmp\" --workdir /tmp --rm convco/convco`

Refs: #86
@hdevalke
Copy link
Collaborator

hdevalke commented Oct 4, 2022

#88 adds better error handling for this case.

If it occurs you will see this in the stderr output:

Error: Could not open the git repository.
If run from docker set the right user id and group id.
E.g. `docker run -u "$(id -u):$(id -g)" -v "$PWD:/tmp" --workdir /tmp --rm convco/convco`

Caused by:
    config value 'safe.directory' was not found; class=Config (7); code=NotFound (-3)

hdevalke added a commit that referenced this issue Oct 12, 2022
If the git repo can't be opened because of the `safe.directory` config a hint will be printed:

> Could not open the git repository.
> If run from docker set the right user id and group id.
> E.g. `docker run -u \"$(id -u):$(id -g)\" -v \"$PWD:/tmp\" --workdir /tmp --rm convco/convco`

Refs: #86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants