Keep your project build sources up to date

cbeams edited this page Aug 29, 2011 · 6 revisions

Scenario: a change has been made to the shared buildSrc submodule, and as the project lead/maintainer, you need to update your project to make use of it. We'll use Spring Integration as an example:

Steps:

1. cd spring-integration/buildSrc

you're now within the submodule, so all git commands are specific to the (buildSrc) submodule, not the parent (spring-integration) project

2. git checkout master; git pull

These commands update your local copy of buildSrc to the latest changes. Issue a git log at this point and review what the latest changes are. You should see the features you're interested in toward the top of the log.

3. cd ..

change directories back to the spring-integration parent project.

3. test changes locally

At this point you can try out the new features in buildSrc locally before committing anything.

4. git status

You should notice the following:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   buildSrc (new commits)
#

This means that your local copy of buildSrc contains commits newer than the one your spring-integration project is currently 'pinned' to.

You can verify this by issuing a git diff buildSrc: you'll see something like the following (exact SHA values will differ):

diff --git buildSrc buildSrc
index dfae802..db44316 160000
--- buildSrc
+++ buildSrc
@@ -1 +1 @@
-Subproject commit dfae80296e48e4e67bf08ceef0ab348b21ed3ce4
+Subproject commit db443164bf02a122f771a2bf4ed72df932779652

This literally means that the buildSrc submodule has been updated to the latter commit, where it was previously 'pinned' at the former commit.

5. git add buildSrc

This command tells git that you want the parent spring-integration project 'pinned' to the latest commit in your updated buildSrc directory. It is, in effect, like calling git add on any other file. Here, the buildSrc submodule is just treated as a kind of special file.

6. git commit; git push

As per usual, this will push your local changes to the remote repository. The remote repository will now be pinned to the new buildSrc commit.

7. Inform developers/contributors of the new changes

Unfortunately, other developers will not automatically get the new buildSrc changes when they issue their next git pull. Rather, they must also issue a git submodule update. You can simply send an email to this effect.


For Spring Integration committers: How to sync up to buildSrc updates

After the SI project lead has sent the email mentioned in step 7 above, here's what you need to do. Note that this is really just your usual day-to-day fork-based synchronization workflow, plus a git submodule update at the end:

cbeams:~/Work/spring-integration/spring-integration[master]>$ git fetch --all
Fetching origin
Fetching upstream
remote: Counting objects: 198, done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 119 (delta 77), reused 109 (delta 68)
Receiving objects: 100% (119/119), 15.11 KiB, done.
Resolving deltas: 100% (77/77), completed with 41 local objects.
From https://github.com/SpringSource/spring-integration
   ee0efee..a97ddfa  master     -> upstream/master`git merge upstream/master`
cbeams:~/Work/spring-integration/spring-integration[master]>$ git merge upstream/master
Updating ee0efee..a97ddfa
Fast-forward
 build.gradle                                       |   15 ++--
 buildSrc                                           |    2 +-
 spring-integration-amqp/pom.xml                    |   88 +++++++++-----------
cbeams:~/Work/spring-integration/spring-integration[master]>$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 8 commits.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   buildSrc (new commits)
#
cbeams:~/Work/spring-integration/spring-integration[master]>$ git submodule update
Submodule path 'buildSrc': checked out 'db443164bf02a122f771a2bf4ed72df932779652'
cbeams:~/Work/spring-integration/spring-integration[master]>$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 8 commits.
#
nothing to commit (working directory clean)
cbeams:~/Work/spring-integration/spring-integration[master]>$ git push origin
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:cbeams/spring-integration.git
   ee0efee..a97ddfa  master -> master
cbeams:~/Work/spring-integration/spring-integration[master]>$ git status
# On branch master
nothing to commit (working directory clean)