Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt.states.git.cloned can't clone into an existing directory #55926

Open
iaingeorgeson opened this issue Jan 21, 2020 · 9 comments
Open

salt.states.git.cloned can't clone into an existing directory #55926

iaingeorgeson opened this issue Jan 21, 2020 · 9 comments
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@iaingeorgeson
Copy link

iaingeorgeson commented Jan 21, 2020

Description of Issue

Attempting to use git.cloned where "target" directory already exists results in an error:

Comment: Command 'git status -z --porcelain' failed: fatal: not a git repository (or any of the parent directories): .git

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

I'm bootstrapping my salt master. Largely untouched Debian buster running latest salt. Applied using
# salt-call --local --file-root=$top/salt --pillar-root=$top/pillar --id=$(hostname -f) state.highstate $@

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

I want to set up a git clone in /srv/salt-master. /srv is root:root 0755. /srv/salt-master is salt:salt 0750. As user "salt" is unable to create a directory in /srv, I use a salt state to create /srv/salt-master:

/srv/salt-master/:
file.directory:
- user: salt
- group: salt
- mode: 0750

and then attempt to clone into it with

clone-bare-repo:
git.cloned:
- name: /srv/git/salt-yhhyt.git/
- target: /srv/salt-master/
- user: salt

Result is


      ID: clone-bare-repo
Function: git.cloned
    Name: /srv/git/salt-yhhyt.git/
  Result: False
 Comment: Command 'git status -z --porcelain' failed: fatal: not a git repository (or any of the parent directories): .git
 Started: 22:32:19.815419
Duration: 118.882 ms
 Changes:   

An alternative attempt replacing git.cloned with this cmd.run is sucessful:

clone-bare-repo:
cmd.run:
- name: git clone /srv/git/salt-yhhyt /srv/salt-master/
- creates: /srv/salt-master/.git/
- runas: salt

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

root@havelock:~/git/salt-yhhyt# salt --versions-report
Salt Version:
Salt: 2019.2.3

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.5
gitpython: 2.1.11
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.7.3 (default, Apr 3 2019, 05:39:12)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 17.1.2
RAET: Not Installed
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.1

System Versions:
dist: debian 10.2
locale: ISO-8859-1
machine: x86_64
release: 4.19.0-6-cloud-amd64
system: Linux
version: debian 10.2

@xeacott
Copy link
Contributor

xeacott commented Jan 22, 2020

Thanks for the report, and including that work around. If you're able to successfully run a cmd.run and achieve the desired results from git.cloned then my inclination is the git state module has something wonky in it.

Have you tried running a git.cloned on another existing repository on your machine to see if the state comes back saying the dir is already a repo?

@xeacott xeacott added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label Jan 22, 2020
@xeacott xeacott added this to the Blocked milestone Jan 22, 2020
@iaingeorgeson
Copy link
Author

I've changed the target to a directory under /tmp and run a few more trials to look at the behaviour.

  • target directory does not exist:
          ID: clone-bare-repo-to-tmp
    Function: git.cloned
        Name: /srv/git/salt-yhhyt.git/
      Result: True
     Comment: /srv/git/salt-yhhyt.git/ cloned to /tmp/salt-master/
     Started: 18:01:46.847388
    Duration: 68.457 ms
     Changes:   
              ----------
              new:
                  /srv/git/salt-yhhyt.git/ => /tmp/salt-master/
  • target is a freshly cloned git repo:
          ID: clone-bare-repo-to-tmp
    Function: git.cloned
        Name: /srv/git/salt-yhhyt.git/
      Result: True
     Comment: Repository already exists at /tmp/salt-master/
     Started: 18:02:59.020916
    Duration: 53.643 ms
     Changes:   
  • target is an empty directory:
          ID: clone-bare-repo-to-tmp
    Function: git.cloned
        Name: /srv/git/salt-yhhyt.git/
      Result: False
     Comment: Command 'git status -z --porcelain' failed: fatal: not a git repository (or any of the parent directories): .git
     Started: 18:03:48.783617
    Duration: 55.707 ms
     Changes:   

This appears to be coming from the git.status test at

__salt__['git.status'](target,

@xeacott
Copy link
Contributor

xeacott commented Jan 22, 2020

Ahh, interesting! Thanks for running a few more tests on it, and it does seem to be coming from the git.status return.

@xeacott xeacott added Bug broken, incorrect, or confusing behavior P4 Priority 4 and removed Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged labels Jan 22, 2020
@xeacott xeacott modified the milestones: Blocked, Approved Jan 22, 2020
@xeacott xeacott added the severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around label Jan 22, 2020
@sagetherage sagetherage removed the P4 Priority 4 label Jun 3, 2020
@rnickle
Copy link

rnickle commented Nov 12, 2020

Just ran into the same issue, thanks for posting.

@jkmcrg
Copy link

jkmcrg commented Apr 18, 2021

same issue - thank you for taking the time to be thorough @iaingeorgeson

@Kubci
Copy link

Kubci commented Apr 26, 2021

Experienced this issue as well:

clone_bla_bla:
git.cloned:
- name: https://auth:token@gitlab.com/valid/git/path.git
- target: /srv/tmp
Correctly clones the repo.

clone_bla_bla:
git.cloned:
- name: https://auth:token@gitlab.com/valid/git/path.git
- target: /srv
Result: False
Comment: Command 'git status -z --porcelain' failed: fatal: not a git repository (or any of the parent directories): .git

@MurzNN
Copy link

MurzNN commented Apr 28, 2021

I got the same problem with git.cloned to empty target directory, workaround with deleting it - helps, but will be good to have better solution!

@cavepopo
Copy link
Contributor

I got this error too, I worked it around by using git.latest.
Just sayin' in case that'd help anyone

@xorinzor
Copy link

Same issue is still present. using git.latest worked for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

9 participants