Search code examples
androidgitgithubrepositorycyanogenmod

repo init a particular commit


Im building the Cyanogenmod 9 (Android ICS) system for a Nexus S phone (samsung crespo). The problem is that if I do:

repo init -u git://github.com/CyanogenMod/android.git -b ics  

The repo inits to the latest commit of ICS, in which the manifest does not include some device/samsung/ projects I need (specifically https://github.com/CyanogenMod/android_device_samsung_crespo).

How do I repo init to a particular commit? In my case I want the last commit using the google android-4.0.3_r1 branch. Is this one:

If I do

repo init -u git://github.com/CyanogenMod/android.git -b commit-hash

Does not work, seems that repo init -b only support the HEAD of a branch.

Thanks in Advance.


Solution

  • Long answer:

    You can't specify a branch name (or SHA, or whatever else) to repo, it will not work. Here's why:

    repo is a script that handles a collection of repository projects (which in fact are independent git's). Project list is located in .repo git, and contains a manifest file, which basically is a list of all repository git's and they branches. -b is relevant only for repo git during repo init.

    Here is an example of .repo/manifests/default.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <manifest>
      <remote fetch="git://address.com/" name="origin"
              review="review.address.com"/>
      <default remote="origin" revision="ics-something" sync-j="4"/>
      <manifest-server url="http://manifests.address.com:8000"/>
      <!-- sniff -->
      <project name="platform/external/libxml2" path="external/libxml2"
               revision="ics-common"/>
      <project name="platform/external/zlib" path="external/zlib"
               revision="ics-common"/>
      <project name="platform/frameworks/base" path="frameworks/base"
               revision="ics-something"/>
      <project name="platform/packages/apps/Bluetooth" path="packages/apps/Bluetooth"
               revision="ics-common"/>
      <!-- sniff -->
    </manifest>
    

    So, the correct way of obtaining the sources of the repository for the particular build is to obtain it's manifest.
    I.e., manifest, that will contain SHA's (or tags, which are practically the same, if they are present) instead of branch names. This way every git project within your repository will point into some commit, that is specified in the manifest file:

    <?xml version="1.0" encoding="UTF-8"?>
    <manifest>
      <remote fetch="git://address.com/" name="origin"
              review="review.address.com"/>
      <default remote="origin" revision="ics-something" sync-j="4"/>
      <manifest-server url="http://manifests.address.com:8000"/>
      <!-- sniff -->
      <project name="platform/external/libxml2" path="external/libxml2"
               revision="refs/tags/android-4.0.4_r1.1"/>
      <project name="platform/external/zlib" path="external/zlib"
               revision="refs/tags/android-4.0.4_r1.1"/>
      <project name="platform/frameworks/base" path="frameworks/base"
               revision="ecb41a77411358d385e3fde5b4e98a5f3d9cfdd5"/>
      <project name="platform/packages/apps/Bluetooth" path="packages/apps/Bluetooth"
               revision="621bae79f1a250e443eb83d1f473c533bea493dc"/>
      <!-- sniff -->
    </manifest>
    

    As you see, the only difference between these two manifests is the revision values of repository git's.

    Short answer:

    You need to obtain manifest_static.xml of the particular build.

    Or, if you just missing some project git's, then you could create local_manifest.xml file in .repo git, add missing git's there, and then repo sync from the root of your repository. More info on local_manifest.xml usage is here.