Bug 2906

Summary: bake checks out git repositories in detached HEAD state
Product: bake Reporter: Tom Henderson <tomh>
Component: bakeAssignee: Daniel Camara <daniel.camara>
Status: RESOLVED FIXED    
Severity: normal CC: adadeepak8, mattator, ns-bugs
Priority: P3    
Version: unspecified   
Hardware: All   
OS: All   
Attachments: Fix the detached state

Description Tom Henderson 2018-04-02 12:40:06 UTC
By default, when a module is specified using git and with no revision, e.g.

    <module name="castxml">
      <source type="git">
        <attribute name="url" value="https://github.com/CastXML/CastXML.git"/>
      </source>
      <build type="cmake" objdir="yes">
        <attribute name="pre_installation" value="mkdir -p $INSTALLDIR/bin"/>
      </build>
      <depends_on name="clang-dev" optional="False"/>
    </module>

Bake will check it out in a detached HEAD state.

 >> Downloading castxml - ()
 git init dir=/path/to/bake/source/tmpb62R3i
Initialized empty Git repository in /path/to/bake/source/tmpb62R3i/.git/
 git remote add origin https://github.com/CastXML/CastXML.git dir=/path/to/bake/source/tmpb62R3i
 git fetch dir=/path/to/bake/source/tmpb62R3i
remote: Counting objects: 3374, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 3374 (delta 7), reused 11 (delta 6), pack-reused 3355
Receiving objects: 100% (3374/3374), 1.15 MiB | 17.05 MiB/s, done.
Resolving deltas: 100% (2357/2357), done.
From https://github.com/CastXML/CastXML
 * [new branch]      master     -> origin/master
 git checkout refs/remotes/origin/master dir=/path/to/bake/source/tmpb62R3i
Note: checking out 'refs/remotes/origin/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c2a44d0... Output: Add original types to decayed function parameters
()

This is also the same state as if a revision is specified (e.g. pybindgen-ns3.27-castxml).  However, I believe that this is correct behavior.

I don't see any API to allow a user to check out a specific branch other than master.

--------

I believe that two changes are needed, but would like feedback from DCE maintainers before making the patch:

1) if no revision or branch is specified, bake should clone the repo and leave it at tip of master branch, and not detached HEAD state

2) API should be added to allow 'branch' to be specified with git; e.g.

        <attribute name="branch" value="my-experimental-branch"/>
        <attribute name="revision" value="3eade768"/>

and the behavior should be that if 'branch' is specified without 'revision', then the local clone should be left at the tip of that branch, but if a past revision is specified, then the local clone should be left in detached HEAD state.
Comment 1 Matthieu Coudron 2018-04-03 12:01:46 UTC
sounds good.
Comment 2 adadeepak8 2018-06-15 03:05:02 UTC
Created attachment 3111 [details]
Fix the detached state

The patch fixes the detached state of git modules if no revision is selected. It also provides the feature to use a specific branch to checkout.
Comment 3 Tom Henderson 2018-06-27 20:45:13 UTC
Pushed in changeset 402:bdb4b6a08c87