检测是否已安装 git lfs

huangapple go评论70阅读模式
英文:

Detect whether git lfs was installed

问题

我正在使用Ansible在我的服务器上设置Git和Git LFS。

当我运行git lfs install时,它会显示:
> Git LFS initialized.

当我再次运行它时,它会显示相同的内容并返回状态码0。这导致Ansible任务不具有幂等性 - 它似乎每次都会安装(而不仅仅是第一次)。

有没有办法检测它是否实际上是通过该命令安装的?或者,如何判断它是否当前已安装?

英文:

I'm using ansible to setup git and git lfs on my server.

When I run git lfs install it says:
> Git LFS initialized.

When I run it again, it says the same thing and returns status code 0. That makes ansible tasks not idempotent - it appears as if it is installed every time (rather than just the first time).

Is there some way to detect whether it was actually installed by that command? Alternatively, how can I tell whether it is currently installed?

答案1

得分: 1

Sure, here's the translated content:

当安装了git lfs时,它会添加内容到 ~/.gitconfig(如果不存在,则会创建)。

它添加了这个:

[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true

我的ansible任务:

- ansible.builtin.shell: "grep '[filter \"lfs\"]' /home/{{ansible_user}}/.gitconfig 2>/dev/null | wc -l"
  register: result
  changed_when: false

- ansible.builtin.command: git lfs install
  when: result.stdout == '0'

如果文件不存在,或存在但不包含文本 [filter "lfs"],则第二个任务将运行 git lfs install

英文:

When git lfs is installed, it adds stuff to ~/.gitconfig (which is created if it does not exist).

It adds this:

[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true

My ansible tasks:

- ansible.builtin.shell: "grep '[filter \"lfs\"]' /home/{{ansible_user}}/.gitconfig 2>/dev/null | wc -l"
  register: result
  changed_when: false

- ansible.builtin.command: git lfs install
  when: result.stdout == '0'

If the file does not exist, or does exist but does not contain the text [filter "lfs"], then the second task will run git lfs install.

huangapple
  • 本文由 发表于 2023年6月29日 12:11:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定