Checkout step failed with submodules

version: 2.1
commands:
  checkoutandverify:
    description: "Checkout and Verify"
    steps:
      - add_ssh_keys:
          fingerprints:
            - "xxxxxx" # test user
      - restore_cache:
          keys:
            - source-v2-{{ .Branch }}
            - source-v2-master
      - checkout
      - run:
          name: "Pull Submodules"
          command: |
            git submodule init
            git submodule update

This repo has two submodules(schema1, schema2). If the commit updates submodules, checkout step will fail. If we remove restore_cache step, everything will work fine.
Here is log for restore_cache step

No cache is found for key: source-v2-sliu_test
Found a cache from build 2176 at source-v2-master
Size: 11 MB
Cached paths:
* /Users/distiller/project/.git

Downloading cache archive...
Validating cache...

Unarchiving cache...

Here is log for checkout step

remote: Enumerating objects: 29, done.        
remote: Counting objects: 100% (29/29), done.        
remote: Compressing objects: 100% (7/7), done.        
remote: Total 40 (delta 21), reused 25 (delta 19), pack-reused 11        
Unpacking objects: 100% (40/40), done.
From github.com:xxxxx/test
 * [new branch]      test  -> origin/test
fatal: exec 'rev-list': cd to 'schema1' failed: No such file or directory
Fetching submodule schema
fatal: cannot chdir to '../../../schema1': No such file or directory
Exited with code 1

I tried to ssh into the machine with restored cache, and run all command line from check out step, everything works fine.

The checkout actually runs a fairly involved shell script - it is not just a git clone. Since you have submodules, it may be worth skipping that step and writing your own. I believe there are enough environment variables available for you to see what branch/hash to checkout to.

We found that if we call git reset --hard before checkout step, the issue can be solved.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.