Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Can't commit on a bare repository #692

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

Merged
merged 1 commit into from
Apr 26, 2014
Merged

Can't commit on a bare repository #692

merged 1 commit into from
Apr 26, 2014

Conversation

nulltoken
Copy link
Member

Could somebody review whether the following test case correct?

[Fact]
public void CanCommitOnBareRepository()
{
    string repoPath = InitNewRepository(true);
    SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
    string workPath = Path.Combine(scd.RootedDirectoryPath, "work");
    Directory.CreateDirectory(workPath);

    RepositoryOptions repositoryOptions = new RepositoryOptions()
    {
        WorkingDirectoryPath = workPath,
        IndexPath = Path.Combine(scd.RootedDirectoryPath, "index")
    }

    using (var repo = new Repository(repoPath, repositoryOptions))
    {
        const string relativeFilepath = "test.txt";
        Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
        repo.Index.Stage(relativeFilepath);

        Assert.NotNull(repo.Commit("Initial commit", Constants.Signature, Constants.Signature));
        Assert.Equal(1, repo.Head.Commits.Count());
        Assert.Equal(1, repo.Commits.Count());
    }
}

@nulltoken nulltoken added the Bug label Apr 25, 2014
@nulltoken
Copy link
Member

@mumitroller Bam! It's a bug. Very nice catch!

I think that this check is the root cause of the issue.

We should always update HEAD target and optionally update the reflog depending on the core.logAllRefUpdates. Current implementation does the opposite (ie. Update the HEAD when core.logAllRefUpdates is set).

Would you feel like sending a Pull Request to fix this? We'd happily support you!

@mumitroller
Copy link
Contributor Author

@nulltoken I have zero knowledge of reflogs so I dont know how to fix the problem properly. The only solution that I can imagine now is just to remove these lines.

nulltoken pushed a commit that referenced this pull request Apr 26, 2014
@nulltoken
Copy link
Member

@mumitroller Actually, my previous idea was unnecessarily complex. Because of some recent work at the libgit2 level, your proposal is enough to fix this issue. As such, I've granted you authorship of the commit above.

@carlosmn While investigating this, I've discovered something weird (see the commented out lines in the test). Shouldn't libgit2/libgit2#2194 guard us against this?

@nulltoken
Copy link
Member

@mumitroller BTW, that was an awesomely crafted failing test! ✨

@carlosmn
Copy link
Member

The fixes from libgit2 should indeed handle this correctly. I'm going to take a look.

@mumitroller
Copy link
Contributor Author

@nulltoken Thank you!


// TODO: Uncomment these lines once this is handled at the libgit2 level
//Assert.Equal(0, repo.Refs.Log("refs/heads/master").Count());
//Assert.Equal(0, repo.Refs.Log("HEAD").Count());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further up, we set the workdir, which means this is no longer a bare repository, so the default is to log updates, so the right number here is 1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh. You're right. I forgot that git_repository_set_workdir() was tweaking the is_bare bit. Thanks for your 👀

I'm going to drop the comments and give LogCommit() is a less terrible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosmn, @nulltoken Just for clarity - we set workdir only for this session, after closing the repository still remain bare. Hint for RepositoryOptions.WorkingDirectoryPath says:

...combined with IndexPath, would allow to work against a bare repository as it was a standard one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository by itself is bare, but you've made your instance non-bare by giving it the workdir, which is what's missing in a bare repo.

@nulltoken nulltoken added this to the v0.18.0 milestone Apr 26, 2014
@nulltoken nulltoken merged commit d8ac9e4 into vNext Apr 26, 2014
@nulltoken nulltoken deleted the ntk/fix/692 branch April 26, 2014 17:04
@nulltoken
Copy link
Member

@mumitroller It's merged. Thanks a lot for this perfect report!

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

Successfully merging this pull request may close these issues.

3 participants