Search code examples
gitgithubgithub-actionsgit-lfs

Error: fatal: --local can only be used inside a git repository


Today when I run the github actions, shows error like this:

Error: fatal: --local can only be used inside a git repository

this is the full log about the actions log:

Run actions/checkout@v3
Syncing repository: RedDwarfTech/cv_render
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/2abd7da7-7754-4217-b5db-2984399b003e' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/cv_render/cv_render
/usr/bin/git config --local --get remote.origin.url
Error: fatal: --local can only be used inside a git repository
Deleting the contents of '/home/runner/work/cv_render/cv_render'
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'28106b95ce29effd8f28340d7e6cbba265a04e71'

and this is my github actions define:

- name: Checkout source
  uses: actions/checkout@v3
  with:
    lfs: false

why did this issue happen? what should I do to fixed this issue? This is the full github actions look liks:

name: cv-render-k8s-pro

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Cache
      uses: actions/cache@v3
      with:
        key: lfs-cache
        path: .git/lfs
        restore-keys: |
          - lfs-cache

    - name: Checkout source
      uses: actions/checkout@v3
      with:
        lfs: false
        
    - name: Install git-lfs
      run: |
        curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
        sudo apt-get install git-lfs

    - name: Set Git LFS default remote URL
      run: |
        git remote set-url origin https://${{ secrets.LFS_USER_NAME }}:${{ secrets.LFS_PASSWORD }}@codeup.aliyun.com/6299c42d487c500c27f5f963/cv_render.git
        git config --global credential.helper store
        git config --global user.email "jiangtingqiang@gmail.com"
        git config --global user.name "jiangchaoquan123456"

    - name: Initialize Git LFS
      run: |
        git lfs install

    - name: Pull LFS files
      run: |
        git lfs pull

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v2

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2

    - name: Login to Docker Hub
      uses: docker/login-action@v2
      with:
        registry: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
        username: ${{ secrets.ALIYUN_DOCKER_REPO_USER_NAME }}
        password: ${{ secrets.ALIYUN_DOCKER_REPO_USER_PASSWORD }}

    - name: Build and push
      uses: docker/build-push-action@v3
      with:
        context: .
        file: Dockerfile
        push: true
        tags: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }} 

    - name: deploy to cluster
      uses: steebchen/kubectl@v2.0.0
      with: 
        config: ${{ secrets.KUBE_CONFIG_DATA }}
        command: set image --record deployment/cv-render-service cv-render-service=${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }} -n reddwarf-pro

    - name: verify deployment
      uses: steebchen/kubectl@v2.0.0
      with:
        config: ${{ secrets.KUBE_CONFIG_DATA }}
        version: v1.21.0
        command: rollout status deployment/cv-render-service -n reddwarf-pro

Solution

  • You're not using the actions/checkout task in the most default setup 😉. It looks like you're trying to use LFS storage from a different storage provider than GitHub.

    Your actions/cache, if successful, will create a .git/lfs folder in the runners working directory. That .git folder isn't a proper git repo, it's missing all kinds of stuff, but it will trigger a number of different routines in the runner as it needs to check whether the repo is usable for this workflow run or needs to be cleaned up. That code fails.

    I'm guessing you can work around the issue by placing the actions/checkout step before the action/cache step. That way there is no .git folder and the actions/checkout step will act as normal on a hosted runner. The actions/cache step can then restore the LFS cache in the .git folder and after that you can change the LFS configuration to sync the rest of the files if needed.