mcc,
@mcc@mastodon.social avatar

Git submodule question. Yes, I know, your advice is probably "don't use submodules". But.

Is it possible to clone a repo with submodules such the submodule branches are "activated" after clone?

Like, in .gitmodules we say:

[submodule "local/path"]
path = local/path
url = remote/path
branch = BRANCHNAME

We hoped branch = BRANCHNAME would make it activate BRANCHNAME on clone. But no, it checks out as "detatched head", which later makes VSCode confused. Can we do better?

mcc,
@mcc@mastodon.social avatar

Okay but seriously though

What… does… this… do?

I have read this chunk of the documentation three times and I cannot figure out what it is trying to communicate :(

mhoye,
@mhoye@mastodon.social avatar

@mcc "should" is really the cherry on top of this.

Specialist_Being_677,
@Specialist_Being_677@hachyderm.io avatar

@mcc it tries to check out a branch instead of just a bare commit (detached head), if they match, I think.

The special thing looks like it's supposed to let your submodule branch be main if your outer is main, and develop if your outer is develop...

But I've never really had this option work for me that I know of... So you've basically had the same experience as me.

Git is full of mysteries.

mcc,
@mcc@mastodon.social avatar

@Specialist_Being_677 that's how i read it, but it's not what i did.

this is what it actually does, i think: https://social.belkadan.com/@jrose/statuses/01HY4FN12S5RMCZJ6CZNRCWW5F

oblomov,
@oblomov@sociale.network avatar

@mcc @Specialist_Being_677 so this is either a big in the behavior or a big in the documentation (lack of clarity)

Flyingmana,
@Flyingmana@phpc.social avatar

@mcc I think what you need is part of the clone command itself.
I found a description here https://stackoverflow.com/a/3797061/716029

mcc,
@mcc@mastodon.social avatar

@Flyingmana i think you're right.

unfortunately, this is not what i want! :( i think the thing i want doesn't exist.

Flyingmana,
@Flyingmana@phpc.social avatar

@mcc you want the "make submodules checked out as soon someone else clones this repository without needing them to tell about it"?
Then I guess you are right :/

mcc,
@mcc@mastodon.social avatar

@Flyingmana What I want is:

  • I do git submodules update --init --recursive
  • The submodules are cloned and the branches are checked out.
  • In submodule A, the commit which is checked out happens to be branch IMPORTANTBRANCH.
  • Git then "activates" that branch, so that the subrepo is no longer in "floating head" mode, and commits to this subrepo go to that branch instead of into a weird hole.
mcc,
@mcc@mastodon.social avatar

@Flyingmana Why I want this:

  • I set up a git setup for someone.
  • They are managing git with Visual Studio Code.
  • Visual Studio Code does not warn you, when you add commits, that you are in detached head mode and that committing is not going to do what you want.
  • I was trying to make things easier for them, so that they could do clones without having to either remember to go manually activate a bunch of branches or risk a weird detached head related screw up
pearl,
@pearl@rrr.sh avatar

@mcc take a look at this! i found a flag to do that and made a repo with a submodule that references itself :)

https://github.com/asyncmeow/git-infinite-recursion

mcc,
@mcc@mastodon.social avatar

@pearl i think the branch tag must do the opposite of what I want :(

Is the idea the branch setting in git modules forces an upgrade to the current value of the listed branch, regardless of what hash the commit specifies?

pearl,
@pearl@rrr.sh avatar

@mcc with --remote-submodules, yes, i think so

mcc,
@mcc@mastodon.social avatar

@pearl do you know, if I don't use remote-submodules, what does it do?

pokeylope,
@pokeylope@mastodon.social avatar

@mcc You can prevent git submodule update from switching the submodule back to a detached HEAD (i.e. deactivating the current branch) by adding update = rebase or update = merge to .gitmodules[1], but I don’t believe there’s a way to have it check out the branch on the initial clone.

[1] The setting from .gitmodules is just used to set the submodule.<name>.update config during init, so in an existing repository you’ll have to run git submodule init again to have it take effect.

ale,
@ale@mastodon.manalejandro.com avatar

@mcc cause submodules are referenced to one commit not for a branch only.

mcc,
@mcc@mastodon.social avatar

@ale as far as you know, what does the branch= option in .gitmodules actually do?

I find a paragraph of text in man gitmodules purporting to explain it, but if it isn't saying it activates the branch, then I don't understand what it is really saying.

richlowe,
@richlowe@hachyderm.io avatar

@mcc @ale When I was suffering through basically this problem (which I never solved), it appeared like "branch" was just looked up as a commit, and made things more confusing

mcc,
@mcc@mastodon.social avatar

@richlowe @ale Hm, that is definitely not what I want

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines