libgit2 / libgit2

A cross-platform, linkable library implementation of Git that you can use in your application.
https://libgit2.org/
Other
9.69k stars 2.41k forks source link

git_repository_set_workdir when update_gitlink == 0 #874

Closed carlocaione closed 12 years ago

carlocaione commented 12 years ago

When update_gitlink == 0, core.worktree is not set at all. The usual behaviour for git with --work-tree= is to modify core.worktree without creating the gitlink. Is this an intended behavior?

carlosmn commented 12 years ago

The documentation says that it only updates it if update_gitlink is true. http://libgit2.github.com/libgit2/#HEAD/group/repository/git_repository_set_workdir

Usual behaviour for git? With what commands? It shouldn't be changing the repository's config just because I'm telling it to assume that the worktree is somewhere else for this run.

carlocaione commented 12 years ago

yay, I read the documentation and on a second thought you are right. The problem here is that i need to do with libgit2 something like

$ git --git-dir=./.git --work-tree=/ init

without creating the gitlink file (becouse, of course, I haven't +w on /)

carlosmn commented 12 years ago

That looks like it's relying on a git bug causing it not to clean up.

There is nothing stopping you from setting core.workdir directly, as what you're doing is very specialised and wrong from the library's perspective.

arrbee commented 12 years ago

When I added this to the API, the existing git_repository_set_workdir() was never creating a gitlink file nor setting the core.worktree config. The old behavior was "set work dir in memory only" for the current session. The new flag is supposed to be a "set work dir permanently" variation. I felt like those were the two common uses for this function.

The situation where the worktree is not writable seems like a somewhat uncommon case to me. Unless you @carlocaione find it really repugnant, I think @carlosmn suggestion to just use git_config_set_string() to directly write to core.workdir is probably the way to go.

Does that sound like an acceptable resolution? If so, I'll add that suggestion to the documentation for git_repository_set_workdir() as a way to have set a persistent separate work dir without creating a gitlink but not make any code changes.

carlosmn commented 12 years ago

Note that a worktree of / is not a supported use-case in git and breaks every once in a while, so we shouldn't be trying to support this too hard. Since git --work-tree=/ --git-dir=.git init without cleaning up is equivalent to

git --bare init .git &&
git --git-dir .git config core.bare false &&
git --git-dir .git config core.worktree /

I'd suggest doing the equivalent with libgit2 and hoping nothing breaks when you update git.