concourse / git-resource

tracks commits in a branch of a Git repository
Apache License 2.0
192 stars 288 forks source link

git_config settings doesn't applied #369

Open maestrow opened 3 years ago

maestrow commented 3 years ago

I have git_config option in git resource. And no one option seems to be applied.

How to reproduce

Assume the following pipeline config saved to git-config.yml:

resources:
- name: repo
  type: git
  icon: github
  source:
    uri: git@github.com:maestrow/concourse-examples.git
    private_key: |
      -----BEGIN OPENSSH PRIVATE KEY-----
      -----END OPENSSH PRIVATE KEY-----
    branch: master
    git_config:
    - name: user.name
      value: conc
    - name: user.email
      value: conc@local.lo
    - name: core.bigFileThreshold
      value: 10m

jobs:
- name: git_config_job
  plan:
  - get: repo
    trigger: true
  - task: create-commit
    config:
      platform: linux
      image_resource:
        type: registry-image
        source:
          repository: gitea/gitea # use any image that has the git cli
      inputs:
      - name: repo
      outputs:
      - name: repo
      run:
        path: sh
        args:
        - -cx
        # git config --global user.name conc
        # git config --global user.email conc@local
        - |
          cd repo
          whoami
          cat ~/.gitconfig
          cat .git/config
          date > todays-date
          git add ./todays-date
          git commit -m "Update todays date"
  - put: repo
    params:
      repository: repo

Set this pipeline: fly -t tutorial set-pipeline -p git_config -c git-config.yml. Then trigger fly -t tutorial trigger-job -j git_config/git_config_job --watch.

Actual result

What we see in output:

running sh -cx cd repo
whoami
cat ~/.gitconfig
cat .git/config
date > todays-date
git add ./todays-date
git commit -m "Update todays date"

+ cd repo
+ whoami
root
+ cat /root/.gitconfig
cat: can't open '/root/.gitconfig': No such file or directory
+ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git@github.com:maestrow/concourse-examples.git
        fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
        remote = origin
        merge = refs/heads/master
+ date
+ git add ./todays-date
+ git commit -m 'Update todays date'
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.

The most important part is /root/.gitconfig: No such file or directory.

Expected result

Anthonyhawkins commented 3 years ago

+1 We are experiencing this exact issue as well.

reshmiasish commented 6 months ago

any solution for this?

mzampetakis commented 4 months ago

I am facing the same issue described here.

I Have this resource:

resources:
  - name: concourse-adapter
    type: git
    icon: git
    source:
      uri: https://seed.radicle.gr/z2woyw9Get9Q21VJzdbVz33b47xDb.git
      git_config:
        - name: safe.directory
          value: /tmp/build/get
        - name: remote.origin.fetch
          value: "+refs/*:refs/remotes/origin/*"
        - name: fetch.all
          value: true

and in my task I have these commands:

  run:
    path: sh
    args:
      - -c
      - |
        cd concourse-adapter
        ls -al ~/
        ls -al /root
        echo $(git config --list)
        echo $(git config --list --global)
        cat ~/.gitconfig

The output indicates that there is no global configuration - only the local :

total 20
drwx------ 2 root root 4096 Apr  9 05:58 .
drwxr-xr-x 1 root root 4096 Apr 19 05:00 ..
-rw-r--r-- 1 root root  571 Apr 10  2021 .bashrc
-rw-r--r-- 1 root root  161 Jul  9  2019 .profile
total 20
drwx------ 2 root root 4096 Apr  9 05:58 .
drwxr-xr-x 1 root root 4096 Apr 19 05:00 ..
-rw-r--r-- 1 root root  571 Apr 10  2021 .bashrc
-rw-r--r-- 1 root root  161 Jul  9  2019 .profile
core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://seed.radicle.gr/z2woyw9Get9Q21VJzdbVz33b47xDb.git remote.origin.fetch=+refs/heads/main:refs/remotes/origin/main branch.main.remote=origin branch.main.merge=refs/heads/main
fatal: unable to read config file '/root/.gitconfig': No such file or directory

cat: /root/.gitconfig: No such file or directory

Has anyone solved this issue somehow?

mzampetakis commented 4 months ago

Maybe @nosdod could share the steps to set it up at it seems that it somehow worked at this issue: https://github.com/concourse/git-resource/issues/383

Can you provide the resource configuration that you set up the git_config ?

jcarrete5 commented 1 month ago

It looks like /root/.gitconfig is updated but you will only see the modifications within the get step. You can use the hijack fly CLI subcommand to inspect the container used in the get step and see that the modifications are made there. I guess that since this configuration is not placed in the output directory, future steps do not see that file. This is probably useful for some config options that affect how git clones repositories like those used in #383. Perhaps it would be wise to also update the local config settings in the repository as well after it is cloned as part of the in script so that future steps can use those configs.