Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track configuration in local git repositories
Fixes #3162.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#! /bin/sh | ||
|
||
set -e | ||
|
||
dir="${1}" | ||
commit_message="${2}" | ||
|
||
if ! [ -d "${dir}" ]; then | ||
# nothing to track | ||
exit 0 | ||
fi | ||
cd "${dir}" | ||
|
||
if ! [ -d ".git" ]; then | ||
git init | ||
fi | ||
|
||
# unconditionally update the config as necessary | ||
git config user.email "{{ track_config['default_author_email'] }}" | ||
git config user.name "{{ track_config['default_author_name'] }}" | ||
|
||
# check for changes | ||
if git status 2>/dev/null | grep -q 'working directory clean'; then | ||
exit 0 | ||
fi | ||
|
||
# use git add --all to capture deletes, too | ||
git add --all . | ||
|
||
# commit the changes | ||
git commit --author='{{ track_config['author_name'] }} <{{ track_config['author_email'] }}>' \ | ||
-m "${commit_message}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
# see #3162 for the background of this technique | ||
- name: track configuration locally | ||
hosts: all | ||
gather_facts: no | ||
connection: local | ||
sudo: yes | ||
tasks: | ||
- name: install track-config.sh | ||
template: | ||
src: "templates/track-config.sh" | ||
dest: "/root/track-config.sh" | ||
mode: 0755 | ||
|
||
- name: track configuration | ||
command: "/root/track-config.sh {{ item }} '{{ commit_message }}'" | ||
with_items: track_config['dirs'] | ||
changed_when: False |