mantisbt:git_submodules
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| mantisbt:git_submodules [2013/08/30 13:15] – created dregad | mantisbt:git_submodules [2014/04/30 13:00] (current) – Added update from within the submodule (phpmailer example) dregad | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Working with Git Submodules in MantisBT ====== | ====== Working with Git Submodules in MantisBT ====== | ||
| - | |||
| - | // | ||
| Some [[3rdpartycode|3rd party libraries]] are stored and maintained in the MantisBT repository | Some [[3rdpartycode|3rd party libraries]] are stored and maintained in the MantisBT repository | ||
| - | using [[http:// | + | using [[http:// |
| This setup requires some special handling when initializing the repository and when switching branches, | This setup requires some special handling when initializing the repository and when switching branches, | ||
| Line 19: | Line 17: | ||
| ===== Switching Branches ===== | ===== Switching Branches ===== | ||
| + | |||
| ==== With Submodules --> No Submodules ==== | ==== With Submodules --> No Submodules ==== | ||
| Line 24: | Line 23: | ||
| Checking out a branch with Submodules when the current branch does not have them. | Checking out a branch with Submodules when the current branch does not have them. | ||
| - | @@@ | + | < |
| + | $ git status | ||
| + | # On branch WithSubmodules | ||
| + | nothing to commit, working directory clean | ||
| + | |||
| + | $ git checkout NoSubmodules | ||
| + | error: The following untracked working tree files would be overwritten by checkout: | ||
| + | (list of files) | ||
| + | Aborting | ||
| + | </ | ||
| + | |||
| + | **Solution 1** | ||
| + | |||
| + | **WARNING**: | ||
| + | Only do this if you are sure that you don't have any pending modifications. | ||
| + | |||
| + | First we force checkout to ignore changes, then we remove all untracked files. | ||
| + | |||
| + | < | ||
| + | $ git checkout --force NoSubmodules | ||
| + | warning: unable to rmdir library/ | ||
| + | warning: unable to rmdir library/ | ||
| + | Switched to branch ' | ||
| + | |||
| + | $ git clean --force | ||
| + | Removing library/ | ||
| + | [...] | ||
| + | Removing library/ | ||
| + | </ | ||
| + | |||
| + | **Solution 2** | ||
| + | |||
| + | This is slightly more complex but safer alternative, | ||
| + | |||
| + | Move the submodules directory to a temporary location, e.g. ''/ | ||
| + | < | ||
| + | $ sed -rn " | ||
| + | $ git checkout NoSubmodules | ||
| + | Switched to branch ' | ||
| + | </ | ||
| + | |||
| + | When switching back from the older branch, the submodules directories will be empty. At that point you can either | ||
| + | |||
| + | * Update the submodules to reclone them (in which case earlier changes will be lost) < | ||
| + | $ git submodule update</ | ||
| + | |||
| + | * Restore the directories previously moved to ''/ | ||
| + | sed -rn " | ||
| + | </ | ||
| ==== No Submodules --> With Submodules ==== | ==== No Submodules --> With Submodules ==== | ||
| Line 30: | Line 77: | ||
| Checking out a branch without Submodules when the current branch has them. | Checking out a branch without Submodules when the current branch has them. | ||
| - | @@@ | + | < |
| + | $ git status | ||
| + | # On branch NoSubmodules | ||
| + | nothing to commit, working directory clean | ||
| + | |||
| + | $ git checkout WithSubmodules | ||
| + | M library/ | ||
| + | M library/ | ||
| + | Switched to branch ' | ||
| + | </ | ||
| + | |||
| + | **Solution** | ||
| + | |||
| + | Use the following command to reset all Submodules to the state of their respective recorded commit: | ||
| + | < | ||
| + | git submodule foreach git checkout -- . | ||
| + | </ | ||
| Line 37: | Line 101: | ||
| Checking out a branch with Submodules when the current branch has the same submodules but pointing to a different commit. | Checking out a branch with Submodules when the current branch has the same submodules but pointing to a different commit. | ||
| - | @@@ | + | For example, branch SubmodulesNew has an updated ADOdb library: |
| + | < | ||
| + | $ git status | ||
| + | # On branch SubmodulesOld | ||
| + | nothing to commit, working directory clean | ||
| + | |||
| + | $ git checkout SubmodulesNew | ||
| + | M library/ | ||
| + | Switched to a new branch ' | ||
| + | </ | ||
| + | |||
| + | **Solution** | ||
| + | |||
| + | Just update the submodule(s)... | ||
| + | |||
| + | < | ||
| + | $ git submodule update | ||
| + | Submodule path ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== Updating a Library' | ||
| + | |||
| + | This section describes the process to update a submodule when a new version of a library has been released upstream. | ||
| + | |||
| + | ==== Updating via an external repository ==== | ||
| + | |||
| + | The example given here are for the ADOdb library, but the same logic should apply (possibly with some variations) to other submodules as well. | ||
| + | We assume that you already have a local repository configured with the appropriate remotes (// | ||
| + | |||
| + | - Update the library' | ||
| + | * Get the latest from upstream < | ||
| + | cd / | ||
| + | git fetch upstream | ||
| + | </ | ||
| + | * Optional: update the //master// branch < | ||
| + | git rebase upstream/ | ||
| + | </ | ||
| + | * Update the branch < | ||
| + | git checkout mantis-1.3 | ||
| + | git merge v5.19 | ||
| + | </ | ||
| + | * Resolve any conflicts | ||
| + | * Push changes to the fork < | ||
| + | git push origin --tags master mantis-1.3 | ||
| + | </ | ||
| + | - Update the submodule | ||
| + | * Go to your local mantisbt repository and update it< | ||
| + | cd / | ||
| + | git checkout master | ||
| + | git pull | ||
| + | </ | ||
| + | * Go to the submodule' | ||
| + | cd library/ | ||
| + | git checkout mantis-1.3 | ||
| + | git pull | ||
| + | cd .. | ||
| + | </ | ||
| + | - Update '' | ||
| + | - Commit the changes < | ||
| + | git commit -a | ||
| + | </ | ||
| + | |||
| + | At this point, checking the submodules' | ||
| + | |||
| + | < | ||
| + | $ git submodule | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | ==== Updating from within the submodule ==== | ||
| + | |||
| + | It's worth mentioning that step 1 above can also be performed straight from the submodule itself (see example below for phpmailer), provided of course that the remotes (origin and upstream) have been properly configured. | ||
| + | |||
| + | **WARNING**: | ||
| + | |||
| + | * Update the submodule from upstream < | ||
| + | cd library/ | ||
| + | git fetch upstream | ||
| + | git rebase upstream/ | ||
| + | git checkout mantis | ||
| + | git merge v5.2.7 | ||
| + | # Resolve conflicts | ||
| + | </ | ||
| + | * Push changes to the fork - **don' | ||
| + | git push origin --tags master mantis | ||
| + | cd .. | ||
| + | </ | ||
| + | * Edit '' | ||
| + | * Commit the changes < | ||
| + | git commit -a | ||
| + | </ | ||
mantisbt/git_submodules.1377882935.txt.gz · Last modified: (external edit)
