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

Why doing git submodule update && git submodule init? #73

Closed
brando90 opened this issue Feb 4, 2023 · 8 comments
Closed

Why doing git submodule update && git submodule init? #73

brando90 opened this issue Feb 4, 2023 · 8 comments

Comments

@brando90
Copy link

brando90 commented Feb 4, 2023

hi @HazardousPeach Alex, apologies if this is a repetitive question. But are you sure this is the standard command to init git submodules:

git submodule update && git submodule init

I have in my other projects:

# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
git submodule update --init --recursive --remote
# - for each submodule pull from the right branch according to .gitmodule file. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
git submodule foreach -q --recursive 'git switch $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master || echo main )'
# - check it's in specified branch. ref: https://stackoverflow.com/questions/74998463/why-does-git-submodule-status-not-match-the-output-of-git-branch-of-my-submodule
git submodule status

Are you sure that isn't more stable? Perhaps all my issues would be solved by using that and no need to add the ad hoc adds I've being doing before I update, init the submodule?

For concreteness I'm doing this for now while I figure out whats going on:

# - I think this pulls the coq projects properly in proverbot
# todo: Q: metalib missing, how do I pull it with original git submodule commands?
# todo, link1: https://stackoverflow.com/questions/74757297/how-do-i-make-sure-to-re-add-a-submodule-correctly-with-a-git-command-without-ma
# todo, link2: https://github.com/UCSD-PL/proverbot9001/issues/59
# todo, link3: https://github.com/UCSD-PL/proverbot9001/issues/60
#rm -rf coq-projects/metalib  # why?
# -  adds the repo to the .gitmodule & clones the repo (the -b option specifies the branch to checkout, might need to pull it later with other commands, see: https://github.com/brando90/diversity-for-predictive-success-of-meta-learning/blob/main/download_meta_dataset_mds.sh for an example)
git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib

# todo: can't make it work: https://stackoverflow.com/questions/74757702/why-is-git-submodules-saying-there-isnt-a-url-when-there-is-one-even-when-i-try, https://github.com/UCSD-PL/proverbot9001/issues/61
# todo: I suggest we use the original lin-alg https://github.com/coq-contribs/lin-alg
#ls coq-projects/lin-alg
#rm -rf coq-projects/lin-alg
git submodule add -f --name coq-projects/lin-algA git@github.com:HazardousPeach/lin-alg-8.10.git coq-projects/lin-alg
@HazardousPeach
Copy link
Contributor

Hey @brando90 ,

Where are you finding that git submodule update && git submodule init? When I grep on both the tip of develop and the tip of master I only see the inits before the updates. Maybe you're on an older version of the code?

@HazardousPeach
Copy link
Contributor

As for the rest of the options, in that script, I don't think you need them in this case. The --init option to git submodule update seems to basically just do git submodule init first automatically. If you've already run git submodule init, then you don't need it. --recursive says to update any submodules inside the submodules from the current project. I don't think there are any submodules in Proverbot9001 that have their own submodules. --remote says to update to the most recent commit in the remote repository. In this case we specifically don't want this, because we don't know what kind of updates might be in the remotes that break our setup. In several cases I've seen commits without a branch that broke compatibility with the versions of Coq we depend on. Finally, the foreach switch part checks out the branch for each project, but that isn't needed if we don't use --remote because we're just tied directly to the commit.

@brando90
Copy link
Author

Hey @brando90 ,

Where are you finding that git submodule update && git submodule init? When I grep on both the tip of develop and the tip of master I only see the inits before the updates. Maybe you're on an older version of the code?

weird I specifically see:

git submodule update && git submodule init

But I suppose your answer implicitly answer my concern? Maybe I have some stale version. Unsure. I usually run:

# -- Git submodule "pull" all submodules (and init it)
# run git submodule update and the && makes sure init is only ran if the first worked  # https://github.com/UCSD-PL/proverbot9001/issues/73, https://stackoverflow.com/questions/75342383/which-should-be-ran-first-git-submodule-update-or-git-submodule-init
#git submodule update && git submodule init
# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
#git submodule update --init --recursive --remote
git submodule update --init --remote
# - updates the current branch with changes from the remote repository, and also updates all the submodules in your project
#git pull --recurse-submodules
#git pull --recurse-submodules --recursive
# - for each submodule pull from the right branch according to .gitmodule file. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
#git submodule foreach -q --recursive 'git switch $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master || echo main )'
# - check it's in specified branch. ref: https://stackoverflow.com/questions/74998463/why-does-git-submodule-status-not-match-the-output-of-git-branch-of-my-submodule
git submodule status

@brando90
Copy link
Author

--recursive says to update any submodules inside the submodules from the current project. I don't think there are any submodules in Proverbot9001 that have their own submodules. --remote says to update to the most recent commit in the remote repository. In this case we specifically don't want this, because we don't know what kind of updates might be in the remotes that break our setup.

beautiful! Just what I needed to know! :D

@brando90
Copy link
Author

Finally, the foreach switch part checks out the branch for each project, but that isn't needed if we don't use --remote because we're just tied directly to the commit.

@HazardousPeach your so helpful and generous. I think this last question will allow me to close this issue.

But your .gitsubmodules don't have a branch or commit inside their .modules file, so I'm not actually sure what you mean with this...Can you clarify how I know the right commit is being use?

@brando90
Copy link
Author

do update and be careful with recursive and remote flags since if that pulls versions that are to new the current script that proverbot has might break

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

No branches or pull requests

2 participants