0

When performing repo sync it pulls the latest commit from a branch even though it is specified to be a specific commit in the manifest xml file. Why is this happening?

The manifest xml file is revision controlled in a repository called repo_example_manifest which has two commits:

two commits in manifest repository

Here is the manifest xml file I have called default.xml in the older commit (tagged as "v1.0"):

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote  name="organization"
           fetch="https://github.com/organization" />

  <project path="bsp" name="repo_example_bsp" remote="organization" revision="master" >
  </project>
  <project path="app" name="repo_example_app" remote="organization" revision="d3cf9feae739666b1e302f4831eca432afd746fd" />
</manifest>

Here is the manifest xml file in the latest commit (tagged as "v2.0"):

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote  name="orgnanization"
           fetch="https://github.com/orgnanization" />

  <project path="bsp" name="repo_example_bsp" remote="orgnanization" revision="master" >
  </project>
  <project path="app" name="repo_example_app" remote="orgnanization" revision="89ba93c3ed67cc45d31aedcb9db47d3ea66fb9a1" />
</manifest>

As you can see, I simply have two repositories that I manage with git-repo:

  1. repo_example_bsp
  2. repo_example_app

I just did this as an example to play a bit with git-repo before I integrate it with my company's projects.

Under the repository "repo_example_app" I have two commits. The most recent commit is 89ba93c3ed67cc45d31aedcb9db47d3ea66fb9a1 and the oldest commit is: d3cf9feae739666b1e302f4831eca432afd746fd.

I did the following in bash when I was in the oldest commit (tagged as "v1.0") in repo_example_manifest:

$ repo init -u https://github.com/organization/repo_example_manifest

The output was:

Downloading manifest from https://github.com/organization/repo_example_manifest

repo has been initialized in C:\Users\Eyal\Documents\repo_example_manifest
Downloading Repo source from https://gerrit.googlesource.com/git-repo

Then I sent the command:

repo sync

and the output was:

repo sync has finished successfully.

The result is that both repos have been pulled and appear now in my files system: Parent repository file system view after repo sync

So far so good...

BUT, the problem is that the commit pulled under the repository "repo_example_app" which is under the folder "app" is commit number 89ba93c3ed67cc45d31aedcb9db47d3ea66fb9a1 which is the newest commit instead of the commit d3cf9feae739666b1e302f4831eca432afd746fd as written in the XML file.

Can someone explain to me what am I doing wrong here?

  • Try `repo init -u https://github.com/organization/repo_example_manifest -b v1.0 && repo sync`. – ElpieKay Feb 18 '21 at 11:47
  • @ElpieKay I tried what you suggested but it didn't work. I got the following messages `fatal: couldn't find remote ref refs/heads/v1.0` followed by `fatal: cannot obtain manifest https://github.com/organization/repo_example_manifest` – Eyal Gerber Feb 18 '21 at 13:03
  • Then try `cd .repo/manifests;git checkout v1.0;cd ../../;repo sync -m default.xml`. – ElpieKay Feb 18 '21 at 13:06
  • @ElipieKay I did what you said and I got the error `fatal: couldn't find remote ref refs/heads/master`. I think this is because I had setup the main branch of my repo to be called "main" instead of "master". I will try and redo the entire example but with "master" as the name of the main branch of the repository. I will update. soon. – Eyal Gerber Feb 18 '21 at 14:27
  • @ElipieKay So I fixed the main branch name to be master and now I don't get an error anymore. However, the solution doesn't work. In the process you mentioned, once I do "git checkout v1.0" the default.xml file that is in the .repo/manifest folder gets updated to reflect the correct XML file. However, once I do repo sync it just doesn't matter. The default.xml file under .repo/manifest and in the main folder both get updated to the latest version and so the behaviour doesn't change. – Eyal Gerber Feb 18 '21 at 16:08
  • Might I add, that I am assuming that I am not supposed to monitor the revision of ".repo" folder and so it is currently ignored using the .gitignore file. – Eyal Gerber Feb 18 '21 at 16:10

1 Answers1

1

I did some more digging and found that someone asked a similar question and the answers provided there actually solved my problem. The answers that I relied on to resolve my issue is:

  1. https://stackoverflow.com/a/19636869/4441211
  2. https://stackoverflow.com/a/24946287/4441211

Let me elaborate a little bit more: There is no need to transition from one commit to another on the repository that manages the manifest "repo_example_manifest" in order to sync. That won't work. Instead, to "transition" from one version of the manifest to another you must use repo init. In my case, I used repo init -u https://github.com/organization/repo_example_manifest but with the addition of -b <LOCATION>.

LOCATION can be either:

  • Branch name - in such a case the most recent commit from that branch will be taken. If the commit from which you want to get the manifest is from an older commit then this won't get you there. See the two other options below:
  • tag name - You can mark the commits from which you want to take the manifest with tags and then get them by simply replacing LOCATION with: refs/tags/<tagname>
  • Specific commit - you can simply get any commit you want even if it is not tagged by simply replacing LOCATION with the entire commit ID SHA.

After you do repo init -u https://github.com/organization/repo_example_manifest -b <LOCATION> simply type repo sync and it works like a charm.