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

submodule.path & submodule.branch is empty #373

Closed
sigurdblueface opened this issue Sep 8, 2021 · 7 comments
Closed

submodule.path & submodule.branch is empty #373

sigurdblueface opened this issue Sep 8, 2021 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed stale Issues/PRs that are marked for closure due to inactivity

Comments

@sigurdblueface
Copy link

I've added two submodules:

 git submodule add https://mygitlab/prometheus monitoring
 git submodule add https://mygitlab/prometheus-rules

.gitmodules file:

[submodule "monitoring"]
	path = monitoring
	url = https://mygitlab/prometheus
[submodule "prometheus-rules"]
	path = prometheus-rules
	url = https://mygitlab/prometheus-rules

go test code snippet:

func FindSubmodules() error {
	repo, err := git.PlainOpen(".")
	if err != nil {
		return err
	}
	cfg, err := repo.Config()
	if err != nil {
		return err
	}
	for key, submodule := range cfg.Submodules{
		log.Printf("key: %s, name: %s, path: %s, url: %s, branch: %s", key, submodule.Name, submodule.Path, submodule.URL, submodule.Branch)
	}
	return nil
}

func TestFindSubmodules(t *testing.T) {
	err := FindSubmodules()
	if err != nil {
		t.Error(err)
	}
}

output of the above code is

=== RUN   TestFindSubmodules
2021/09/08 13:02:16 key: prometheus-rules, name: prometheus-rules, path: , url: https://mygitlab/prometheus-rules, branch: 
2021/09/08 13:02:16 key: monitoring, name: monitoring, path: , url: https://mygitlab/prometheus, branch: 

Please clarify if it's expected.

@andrewpollock
Copy link
Contributor

andrewpollock commented Oct 10, 2023

I'm seeing something related, where the repo's submodule status is different after code has examined it, than before.

Steps to reproduce:

$ git clone https://github.com/charlesneimog/pd-server.git
Cloning into 'pd-server'...
remote: Enumerating objects: 849, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 849 (delta 2), reused 4 (delta 2), pack-reused 839
Receiving objects: 100% (849/849), 2.12 MiB | 2.56 MiB/s, done.
Resolving deltas: 100% (371/371), done.
$ cd pd-server
$ git submodule update --init --recursive
Submodule 'pd-lib-builder' (https://github.com/pure-data/pd-lib-builder) registered for path 'pd-lib-builder'
Submodule 'src/cpp-httplib' (https://github.com/yhirose/cpp-httplib) registered for path 'src/cpp-httplib'
Submodule 'src/json' (https://github.com/nlohmann/json) registered for path 'src/json'
Submodule 'src/websocketpp' (https://github.com/zaphoyd/websocketpp) registered for path 'src/websocketpp'
Cloning into '/tmp/pd-server/pd-lib-builder'...
Cloning into '/tmp/pd-server/src/cpp-httplib'...
Cloning into '/tmp/pd-server/src/json'...
Cloning into '/tmp/pd-server/src/websocketpp'...
Submodule path 'pd-lib-builder': checked out '5c2e137f7a7a03f4007494954ccb3e23753e7807'
Submodule path 'src/cpp-httplib': checked out '227d2c20509f85a394133e2be6d0b0fc1fda54b2'
Submodule path 'src/json': checked out '4c6cde72e533158e044252718c013a48bcff346c'
Submodule path 'src/websocketpp': checked out '1b11fd301531e6df35a6107c1e8665b1e77a2d8e'
$ git submodule status
 5c2e137f7a7a03f4007494954ccb3e23753e7807 pd-lib-builder (v0.6.0-28-g5c2e137)
 227d2c20509f85a394133e2be6d0b0fc1fda54b2 src/cpp-httplib (v0.11.3-6-g227d2c2)
 4c6cde72e533158e044252718c013a48bcff346c src/json (v3.11.2-39-g4c6cde72)
 1b11fd301531e6df35a6107c1e8665b1e77a2d8e src/websocketpp (0.8.2-1-g1b11fd3)
[run the code in https://github.com/google/osv-scanner/pull/581 against the repo]
$ go run ./cmd/osv-scanner -r /tmp/pd-server/
Scanning dir /tmp/pd-server/
Scanning /tmp/pd-server/ at commit cf3f15a841ca21b53c6de654c9981a30ae0b590c
Scanning submodule src/cpp-httplib at commit 0000000000000000000000000000000000000000
Scanning submodule pd-lib-builder at commit 5c2e137f7a7a03f4007494954ccb3e23753e7807
Scanning submodule src/json at commit 0000000000000000000000000000000000000000
Scanning submodule src/websocketpp at commit 0000000000000000000000000000000000000000
.
.
.
$ git submodule status
 5c2e137f7a7a03f4007494954ccb3e23753e7807 pd-lib-builder (v0.6.0-28-g5c2e137)
 227d2c20509f85a394133e2be6d0b0fc1fda54b2 src/cpp-httplib ()
 4c6cde72e533158e044252718c013a48bcff346c src/json ()
 1b11fd301531e6df35a6107c1e8665b1e77a2d8e src/websocketpp ()
$ git status
On branch master
Your branch is up to date with 'origin/master'.

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)
  (commit or discard the untracked or modified content in submodules)
        modified:   src/cpp-httplib (untracked content)
        modified:   src/json (untracked content)
        modified:   src/websocketpp (untracked content)

@pjbgf pjbgf added bug Something isn't working help wanted Extra attention is needed labels Oct 11, 2023
@andrewpollock
Copy link
Contributor

andrewpollock commented Oct 26, 2023

For reasons not yet clear to me, using SubmoduleStatus Expected instead of Current seems to do the right thing.

Credit to @another-rex for identifying this.

andrewpollock added a commit to andrewpollock/osv-scanner that referenced this issue Oct 26, 2023
@andrewpollock
Copy link
Contributor

So while using Expected instead of Current addresses the unexpected functional issues I was encountering, it does not address the unexpected side-effects to the current state of the submodules.

@pjbgf
Copy link
Member

pjbgf commented Oct 26, 2023

@andrewpollock We could improve the documentation to highlight the behaviour. Would you be keen on proposing a PR to that effect?

@andrewpollock
Copy link
Contributor

@pjbgf Unfortunately I don't feel like I (yet) have enough of a handle on what's actually going on under the hood to be able to do that.

@andrewpollock
Copy link
Contributor

Latest debugging for the unexpected side-effects, I have a narrower reproduction case in https://gist.github.com/andrewpollock/0c51ca92fdb77f1b0671a69c8187d949

$ git clone --recursive https://github.com/charlesneimog/pd-server
Cloning into 'pd-server'...
remote: Enumerating objects: 852, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 852 (delta 3), reused 7 (delta 2), pack-reused 839
Receiving objects: 100% (852/852), 2.12 MiB | 2.26 MiB/s, done.
Resolving deltas: 100% (372/372), done.
Submodule 'pd-lib-builder' (https://github.com/pure-data/pd-lib-builder) registered for path 'pd-lib-builder'
Submodule 'src/cpp-httplib' (https://github.com/yhirose/cpp-httplib) registered for path 'src/cpp-httplib'
Submodule 'src/json' (https://github.com/nlohmann/json) registered for path 'src/json'
Submodule 'src/websocketpp' (https://github.com/zaphoyd/websocketpp) registered for path 'src/websocketpp'
Cloning into '/tmp/pd-server/pd-lib-builder'...
remote: Enumerating objects: 711, done.
remote: Counting objects: 100% (126/126), done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 711 (delta 82), reused 80 (delta 68), pack-reused 585
Receiving objects: 100% (711/711), 176.16 KiB | 751.00 KiB/s, done.
Resolving deltas: 100% (356/356), done.
Cloning into '/tmp/pd-server/src/cpp-httplib'...
remote: Enumerating objects: 4723, done.
remote: Counting objects: 100% (4723/4723), done.
remote: Compressing objects: 100% (1505/1505), done.
remote: Total 4723 (delta 3214), reused 4586 (delta 3168), pack-reused 0
Receiving objects: 100% (4723/4723), 2.79 MiB | 3.91 MiB/s, done.
Resolving deltas: 100% (3214/3214), done.
Cloning into '/tmp/pd-server/src/json'...
remote: Enumerating objects: 36542, done.
remote: Counting objects: 100% (812/812), done.
remote: Compressing objects: 100% (217/217), done.
remote: Total 36542 (delta 386), reused 736 (delta 356), pack-reused 35730
Receiving objects: 100% (36542/36542), 177.61 MiB | 21.22 MiB/s, done.
Resolving deltas: 100% (22578/22578), done.
Cloning into '/tmp/pd-server/src/websocketpp'...
remote: Enumerating objects: 12791, done.
remote: Counting objects: 100% (1549/1549), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 12791 (delta 1504), reused 1353 (delta 1352), pack-reused 11242
Receiving objects: 100% (12791/12791), 8.37 MiB | 8.28 MiB/s, done.
Resolving deltas: 100% (7985/7985), done.
Submodule path 'pd-lib-builder': checked out '5c2e137f7a7a03f4007494954ccb3e23753e7807'
Submodule path 'src/cpp-httplib': checked out 'a609330e4c6374f741d3b369269f7848255e1954'
Submodule path 'src/json': checked out '4c6cde72e533158e044252718c013a48bcff346c'
Submodule path 'src/websocketpp': checked out '1b11fd301531e6df35a6107c1e8665b1e77a2d8e'
$ go run ./gitsubmodulestatusdebug/gsmsd.go 
Hello, world.
[]*git.Repository{(*git.Repository)(0xc00018e0c0), (*git.Repository)(0xc00018e450), (*git.Repository)(0xc00018e750), (*git.Repository)(0xc00018ed50)}
$ git submodule status
 5c2e137f7a7a03f4007494954ccb3e23753e7807 pd-lib-builder (v0.6.0-28-g5c2e137)
 a609330e4c6374f741d3b369269f7848255e1954 src/cpp-httplib ()
 4c6cde72e533158e044252718c013a48bcff346c src/json ()
 1b11fd301531e6df35a6107c1e8665b1e77a2d8e src/websocketpp ()

So the misbehaviour is somewhere within

func (s *Submodule) Repository() (*Repository, error) {

Copy link

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Mar 15, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed stale Issues/PRs that are marked for closure due to inactivity
Projects
None yet
Development

No branches or pull requests

3 participants