Skip to content

Commit ccfd15b

Browse files
committed
manage git alias and git config keys via ansible
1 parent b733ec7 commit ccfd15b

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

roles/git/tasks/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,25 @@
1212
mode: 0644
1313
become: yes
1414
become_user: "{{ ansible_env.SUDO_USER }}"
15+
16+
- name: Supply default configuration entries in ~/.gitconfig
17+
git_config:
18+
name: "{{ item.key }}"
19+
value: "{{ item.value }}"
20+
scope: global
21+
with_dict:
22+
# basic settings
23+
core.autocrlf: input
24+
pull.rebase: 'true'
25+
# useful aliases
26+
alias.co: checkout
27+
alias.ci: commit
28+
alias.br: branch
29+
alias.st: status
30+
alias.unstage: reset HEAD --
31+
alias.slog: log --pretty=oneline --abbrev-commit
32+
alias.graph: log --all --oneline --graph --decorate
33+
alias.stash-all: stash save --include-untracked
34+
alias.prune: fetch --prune
35+
become: yes
36+
become_user: "{{ ansible_env.SUDO_USER }}"

spec/test_git.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import os
23

34
def test_git_package_is_installed_(host):
@@ -15,4 +16,27 @@ def test_git_shell_prompt_is_configured_in_bashrc_d_(host):
1516
assert git_ps1.contains('export PS1=')
1617

1718
def test_git_shell_prompt_is_set_in_the_environment_(host):
18-
assert '__git_ps1' in host.run('bash -i -c "env | grep ^PS1=; exit \\$?"').stdout
19+
assert '__git_ps1' in host.run('bash -i -c "env | grep ^PS1=; exit \\$?"').stdout
20+
21+
22+
def test_gitconfig_configures_rebase_on_pull_(host):
23+
__assert_git_config(host, 'pull.rebase', 'true')
24+
25+
def test_gitconfig_configures_autocrlf_input_(host):
26+
__assert_git_config(host, 'core.autocrlf', 'input')
27+
28+
@pytest.mark.parametrize('shortcut,command', [
29+
('co', 'checkout'),
30+
('ci', 'commit'),
31+
('br', 'branch'),
32+
('st', 'status'),
33+
('unstage', 'reset HEAD --'),
34+
('slog', 'log --pretty=oneline --abbrev-commit'),
35+
('graph', 'log --all --oneline --graph --decorate')
36+
])
37+
def test_gitconfig_provides_alias_(host, shortcut, command):
38+
__assert_git_config(host, f"alias.{shortcut}", command)
39+
40+
def __assert_git_config(host, config_key, expected_value):
41+
actual_value = host.run(f"git config --global --get {config_key}").stdout.strip()
42+
assert actual_value == expected_value

0 commit comments

Comments
 (0)