How to specify the submodule branch in gitlab-ci? - continuous-integration

How to specify branch in .gitlab-ci.yml for a submodule (different repo) in gitlab-ci?

You don't. You specify it in the .gitmodules file of the project you are building.
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master

Along with #stefan's answer to this question. You also have to tell Git to only look at the specified branch for the latest commit. git submodule update seems to always fetch the latest commit regardless of the branch. Doing git submodule update --remote seems to force git to focus on the branch you specify in the .gitmodules file.
So in your .gitmodules files, as #stefen mentions:
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
Then in your GitLab .gitlab-ci.yml file, you need to specify to only look at the configured branch when setting up submodules. My file includes this before_script:
# GitLab CI provides a variable "GIT_SUBMODULE_STRATEGY" that sets up submodules automatically
# But then branch tracking doesn't work (doesn't seem to allow for specifying the --remote) flag
before_script:
- git submodule sync --recursive
- git submodule update --init --remote --recursive
According to documentation, this before_script is the same functionality as provided by GIT_SUBMODULE_STRATEGY (except that I can add the --remote flag to the before_script): https://docs.gitlab.com/ee/ci/yaml/README.html#git-submodule-strategy

Related

Why do am i getting error 404 on my sub module symlink found on my git repo?

I'm currently having an issue with my git submodule. I've created a git submodule in my cloned project folder and it appears right on my repo. But when I click on the symlink, it gives me Error 404 page not found. I am VS Code and Windows 8 x64. Thanks a lot for your help! Below is what is written in the .gitmodules
[submodule "themes/casper-two"]
path = themes/casper-two
url = "https://github.com/eueung/hugo-casper-two"
I cannot find the caa182b commit in the hugo-casper-two repository, so I believe you need to update the submodule to the latest commit available. To do this, run the following command from your project directory:
git submodule foreach git pull origin master
This command will update every submodule in your project and pull the latest commit from their master branch.
Remember to commit your own repository afterwards.
git commit -am "Pulled down updates to submodules"

Google Cloud Build - Cant Update Submodules

I configured google cloud build (GCB) to trigger a build on one of my repositories in Github. This repository requires another git repository in order to be built. This other repository is configured using a git submodule.
I search and at the moment it looks like GCB do not support submodules. So I am trying to run git submodule update --init manually on the source code that GCB downloaded, but there is not .gitdirectory on it and the command fails.
What am I missing here?
I am using this issue as reference: https://github.com/GoogleCloudPlatform/cloud-builders/issues/435
If trigger your build using github it will not work because of the lack of the .git folder. In order for it to work, all repositories need to be mirrored by Cloud Source Repositories. Then, the submodule can be updated like this:
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
git config -f .gitmodules submodule.[my-sub-repo-name].url https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
git submodule init
git submodule update
Ref: https://github.com/GoogleCloudPlatform/cloud-builders/issues/26
Sometimes you get an error with GIT_DISCOVERY_ACROSS_FILESYSTEM or the missing .git folder. The following worked for me:
- id: git-submodule
name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
env: ['GIT_DISCOVERY_ACROSS_FILESYSTEM=1']
args:
- '-c'
- |
git init
git config -f .gitmodules submodule.[my-sub-repo-name].url https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
git submodule init
git submodule update
For someone like me, who is using submodules in Bitbucket and ran into similar problems with Cloud Build: As soon as you mirror your repositories into the Cloud Source Repository, the submodule URLs are not allowed to have the .git extension.
For example for the main repository https://source.cloud.google.com/Project_ID/main_repo and submodules a, b in the "submodules" folder the .gitmodules configuration might look similar to this
[submodule "submodules/a"]
path = submodules/a
url = ../a
[submodule "submodules/b"]
path = submodules/b
url = ../b
Previously, I used for URLs ../a.git and ../b.git which works fine in Bitbucket but not in Cloud Source Repository.

GitHub - How to copy from one branch to another

I git cloned one GitHub repo and checked out one branch.
Then made changes to several files.
How to create another branch and push all changes to a new branch (create new branch and push changes to it using terminal commands)?
Assuming you haven't committed anything yet, you can just use checkout -b to create a new branch, then commit your changes:
$ git clone ...
$ git checkout original-branch
(Make changes)
$ git checkout -b new-branch
$ git commit -a -m "Message for changes"
You talked about "pushing changes" to a new branch - the above would commit the changes in the new branch to the local repo. If you wanted to then push that branch back to GitHub, you'd want something like:
# Here origin is the name of the remote to push to, and new-branch is the branch
$ git push origin new-branch
You'd probably want to make sure you were pushing to your fork rather than to the original repo. You can configure each branch to default to a particular remote and branch, and there are various ways of configuring the default push behavior for new branches too via the push.default configuration option. See the git push docs for more details.

Deploying Laravel workbench projects through composer

I've created several private repos that I'm working on through Laravel 4.2's workbench feature.
How do I get composer to also install/update all the git submodules in the workbench dir on the production server when it updates the vendor dir for the main project?
Why you force composer to do that ?.
I guess you have following project pattern.
Project - A that have many private repo (submodules). for eg: you can add a blog module(Individual Private repo) as submodule to the Project - A .
like
git submodule add path_to_private_repo_for_blog workbench/Vendor_folder/blog.
Once you created all the individual repo as submodule like above. then you can get update using following command.
git pull && git submodule foreach git pull origin master
so simply you can update and deploy the Project -A with following command.
git pull && git submodule foreach git pull origin master && git add -A && git commit -m 'updated pakages' && git push && envoy run update
hope it make sense..

Share sub-project in git repository in another repo

I have a git repository containing a Visual Studio solution with several projects. I have another git repository (also VS) where I want to add one of the projects in the first repo:
Repo 1:
Project_1
Project_2
Project_3
Repo 2:
Project_4
Project_5
Project_1 (Same as Project_1 above)
Is it possible to share just one of the projects in the git repo with another git repository? When I work in the second repo I want to be able to do commit/pull/push to the project that belongs to the first repo, and when I open the first repo I want to be able to get the changes I made to the first project in the second repo.
I have looked at git submodules but I don´t think that would help me since I don´t want to extract the shared project from the first git repo into a separate one. I want to keep the first repo intact...
I think you may be confused on the structure of a git repository. The way I would structure your project is to make a repository for each of the projects then add them to Repo 1 and Repo 2 super projects.
Graphically
Git # Main git project directory
/Projects
/Project_1 # Each one is its own Git repository
/Project_2
/Project_3
/Project_4
/Project_5
/Repos # The main repositories that utilize the projects
/Repo_1 # The super project directory
.gitmodules # The .gitmodules file created by 'git submodules add'
--> submodule with url=../../Projects/Project_1 # entry in .gitmodules
--> submodule with url=../../Projects/Project_2
--> submodule with url=../../Projects/Project_3
/Repo_2
.gitmodules
--> submodule with url=../../Projects/Project_1
--> submodule with url=../../Projects/Project_4
--> submodule with url=../../Projects/Project_5
Since the submodule urls for Project_1 point to the same location, when you git push in one of the submodule directories for Repo_1 or Repo_2 you're actually pushing the changes to the same project repository.
There are some gotchas about synchronizing changes across the two super projects as git allows for the same submodule in two different super repositories to point to different revisions. For more information (such as how to push, commit changes and update submodules) I recommend you checkout:
http://speirs.org/blog/2009/5/11/understanding-git-submodules.html
http://git-scm.com/book/ch6-6.html

Resources