---

- name: Check if carta repo exists
  stat:
    path: "{{carta_repo_directory}}"
  register: carta_directory

- name: Stash any local carta edits
  command: git stash --all
  args:
    chdir: "{{carta_repo_directory}}"
  when: carta_directory.stat.exists
  register: git_stash
  changed_when: "'No local changes to save' not in git_stash.stdout"
  failed_when: false

- name: Sync carta repo
  git:
    repo: git@git.zooxlabs.com:zooxco/carta.git
    dest: "{{carta_repo_directory}}"
    update: yes
    depth: 1
    version: "{{carta_repo_version}}"
    accept_hostkey: yes
    # ug=rwx,o=rx. this permits multiple zoox-group users to run the setup
    # script on a shared machine.
    umask: "002"

- name: Prune old Git LFS content in carta repo
  command:
    cmd: git -c lfs.pruneoffsetdays=0 lfs prune
    chdir: "{{carta_repo_directory}}"
