---
- name: Clear lost+found directory
  # The driving repository is inside an lvm partition.
  # git clone will fail if the target directory isn't empty.
  file:
    path: "{{ driving_repo_dir }}/lost+found"
    state: absent
  become: yes

- name: Check if driving repo exists
  stat:
    path: "{{ driving_repo_dir }}"
  register: driving_repository

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

- name: Clone driving repo
  git:
    repo: git@git.zooxlabs.com:zooxco/driving.git
    dest: "{{ driving_repo_dir }}"
    version: "{{ driving_sha }}"
    clone: yes
    update: yes
    force: yes
