Skip to content

git clones in containers cannot fetch other branches #1929

Closed

Description

@sqqqrly

Bug Report

When I look at the clone inside my container created by concourse (CC) for unit testing, I see a git config that is incorrect (or at least inflexible). The config prevents me from being able to fetch branches.

I want to use a passed-unit-tests branch in my repo-under-test and have CC rebase the passed-unit-tests branch on the tested branch. Then push the passed-unit-test branch back to origin. In this way, I can record in github that the UT passed on the tested commit.

I am unable to git fetch passed-unit-tests or any other branch other than develop.

Cause (.git/config):
fetch = +refs/heads/develop:refs/remotes/origin/develop
Solution:
fetch = +refs/heads/*:refs/remotes/origin/*

A snippit that works around the issue it in my bash script:

      40     info "+++ Remove git origin"
      41     git remote rm origin               || die "git remote rm origin failed"
      42
      43     info "+++ Add git origin"
      44     git remote add origin \
      45         "https://github.com/$gh_user/cc_test_app.git" || die "Cannot add git origin"

Alternative work around, but needing to handle branches other than develop:

sed -i -- 's?fetch = +refs/heads/develop:refs/remotes/origin/develop?fetch = +refs/heads/*:refs/remotes/origin/*?g' .git/config || die "git config fix failed"

Related to:
https://stackoverflow.com/questions/945654/git-checkout-updating-paths-is-incompatible-with-switching-branches
See the answer from Jul 5 '13 at 9:33 PålOliver

  • Concourse version: 3.6.0
  • Deployment type (BOSH/Docker/binary): docker-compose
  • Infrastructure/IaaS: None
  • Browser (if applicable): N/A
  • Did this used to work? No idea

Activity

  1. srbry commented on Jan 2, 2018

    @srbry
    Contributor

    @sqqqrly It feels like you should use multiple resources for this. For example:

    resources:
    - name: test-git
      type: git
      source:
        uri: my-git-repo.git
        branch: master
    - name: test-passed-unit-tests-git
      type: git
      source:
        uri: my-git-repo.git
        branch: passed-unit-tests
    

    You could then have both resources as an input to your task, do some merging etc.

  2. sqqqrly commented on Jan 2, 2018

    @sqqqrly
    Author

    I could, that is a good idea.

    Although, when I add passed-integration-tests, passed-system-tests, passed-staging-tests, etc., the number of resources is starting to explode.
    Plus, I cannot do a simple rebase if they are two different clones...not easily anyway.
    All that for really for no reason...branches should be cheap in git+CC.

    Still seems like a bug. Is there a reason for restricting git like this?

  3. sqqqrly commented on Jan 3, 2018

    @sqqqrly
    Author

    Two resource, one for each branch, as @srbry suggested worked with:

    function commit_to_branch {
        local -r br="$1"
    
        pushd ${cc_test_app_dir} > /dev/null
            # Create a branch named tested_branch from the tested commit
            local -r tested_commit="$(git rev-parse HEAD)"
            git branch tested_branch "$tested_commit" || die "git branch tested_branch $tested_commit failed"
        popd > /dev/null
    
        info "Commit to $br branch. Move HEAD to $tested_commit"
    
        pushd cc-test-app-repo-passed-unit-tests > /dev/null
            # Add and fetch tested_remote. Then rebase on it.
            git remote add tested_remote ../cc-test-app-repo || die "git remote add tested_remote failed"
            git fetch tested_remote || die "git fetch tested_remote failed"
            git rebase tested_remote/tested_branch || die "git rebase tested_remote/tested_branch failed"
        popd > /dev/null
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions