Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

submodules path in gitdir is wrong (was: Submodules not having any objects) #413

Closed
Cromel opened this issue Jun 7, 2017 · 6 comments
Closed
Labels

Comments

@Cromel
Copy link
Contributor

Cromel commented Jun 7, 2017

When you use submodule and get repository it doesnt contain any objects like commits and etc.
It must be becouse they are contained in models directory https://git-scm.com/docs/git-submodule#git-submodule-absorbgitdirs, when in code it is hardcoded "module" in file storage/filesystem/internal/dotgit/dotgit.go
Is it intended in such a way or its a bug?

@smola
Copy link
Collaborator

smola commented Jun 7, 2017

@Cromel Thank you for taking the time for filling this bug report!

Could you post here a small code example showing what you're doing?

@Cromel
Copy link
Contributor Author

Cromel commented Jun 7, 2017

@smola yes, no problem. For example such code doesn't print any commits in repo with submodules:

` path := "some repo with submodules"

r, _ := git.PlainOpen(path)
wt, _ := r.Worktree()
submodules, _ := wt.Submodules()
for _, submodule := range submodules {
	subRep, _ := submodule.Repository()
	commits, _ := subRep.CommitObjects()
	commits.ForEach(func(c *object.Commit) error {
		fmt.Println(c)
		return nil
	})
}`

@smola
Copy link
Collaborator

smola commented Jun 7, 2017

@Cromel Using submodules in a repository requires initializing them (as in git submodule init or git clone --recurse-submodules). Does the repository in path have initialized submodules?

If it does not, you'd have to add the following:

// after getting submodules
err := submodules.Init()
checkErr(err)
err := submodules.Update(&SubmoduleUpdateOptions{})
checkErr(err)

Check SubmoduleUpdateOptions for possible options. Also, if you're cloning with go-git, consider using RecurseSubmodules in CloneOptions.

@Cromel
Copy link
Contributor Author

Cromel commented Jun 7, 2017

@smola repo was cloned using git clone --recurse-submodules , so there are initialized. The problem is with where submodules info is stored. If i change the line in file storage/filesystem/internal/dotgit/dotgit.go
from
modulePath = "module"
to
modulePath = "modules"
its starts working. But i dont know that it is a bug or i do something wrong when i am using submodules.

@smola
Copy link
Collaborator

smola commented Jun 7, 2017

@Cromel Right. It is indeed a bug. It should be modules, so it works if you initialize (with the wrong path) from go-git, but not if it was initialized from git.

Your proposed fix seems correct. Will you create a PR?

@smola smola changed the title Submodules not having any objects submodules path in gitdir is wrong (was: Submodules not having any objects) Jun 7, 2017
@smola smola added the bug label Jun 7, 2017
@Cromel
Copy link
Contributor Author

Cromel commented Jun 8, 2017

@smola Created PR

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

No branches or pull requests

2 participants