Py学习  »  Git

使用puppet使git命令行色彩丰富

Developer • 4 年前 • 644 次点击  

我正在尝试使用木偶使git命令行丰富多彩并出错。我错过了什么?

exec { 'make-git-color':
  command => '/usr/bin/git config --global color.ui auto',
  logoutput => 'on_failure',
  user      => 'vagrant',
  timeout   => 1200,
  require   => Package['git']
}

错误是:

 /Exec[make-git-color]/returns: fatal: $HOME not set
Error: '/usr/bin/git config --global color.ui auto' returned 128 instead of one of [0]

直接运行的命令可以正常工作。 /usr/bin/git config --global color.ui auto

但我需要通过木偶来完成。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38799
 
644 次点击  
文章 [ 3 ]  |  最新文章 4 年前
Developer
Reply   •   1 楼
Developer    5 年前

我使用文件实现了这项工作。

file { '/home/vagrant/.gitconfig':
    content => "[color]\n        ui = auto",
    owner   => 'vagrant',
    group   => 'vagrant',
    require => Package['git'],
  }

但亚历克斯上面给出的答案可能是正确的。现在就试试看:)

John Bollinger
Reply   •   2 楼
John Bollinger    5 年前

错误消息显示 git 在抱怨 HOME 未设置环境变量。其他答案描述了如何为这个变量提供一个值,但这不一定是处理这个特定问题的正确方法。

考虑到这个事实 吉特 关心 建议它尝试在每个用户级别设置配置。如果这确实是你想要的,那就好了,但通过木偶做似乎有点过分了。 VS . 直接运行命令。另一方面,如果是“-global”,你认为你是在 全系统范围 水平,然后你会有惊喜。 git config --global 设置“全局”配置,以影响所有 特定用户的 存储库(不会覆盖它)。通过选择系统范围的属性 --system 选项:

exec { 'make-git-color':
  command => '/usr/bin/git config --system color.ui auto',
  logoutput => 'on_failure',
  user      => 'vagrant',
  timeout   => 1200,
  require   => Package['git'],
  unless    => 'git config --list --system | grep -q color.ui=auto',
}

在这种情况下,您还应该考虑作为用户“vagrant”运行该命令是否合适,因为不清楚该用户是否具有修改系统范围配置的适当权限。

您还应该考虑是否需要这么长的超时时间。我不太明白你所期望的那种情况,在这种情况下,你需要那么长的时间才能有合理的信心相信命令已经挂起了。

Alex Harvey
Reply   •   3 楼
Alex Harvey    5 年前

如错误消息所示,未设置$home。您需要将代码更改为类似这样的内容,以设置缺少的环境变量:

exec { 'make-git-color':
  command     => '/usr/bin/git config --global color.ui auto',
  logoutput   => 'on_failure',
  user        => 'vagrant',
  environment => 'HOME=/home/vagrant',
  require     => Package['git']
}

那就行了(我测试过)。用于将环境变量传递给exec的文档有 here .

注意我也删除了超时,这不是必需的。

如果您还需要确保等幂,根据下面的注释,将其更改为:

exec { 'make-git-color':
  command     => 'git config --global color.ui auto',
  unless      => 'git config --list --global | grep -q color.ui=auto',
  path        => '/usr/bin',
  logoutput   => 'on_failure',
  user        => 'vagrant',
  environment => 'HOME=/home/vagrant',
  require     => Package['git']
}