diff --git a/.editorconfig b/.editorconfig index a0e09f1..d16f02f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,6 @@ indent_size = 2 [Makefile] indent_style = tab + +[*.txt] +trim_trailing_whitespace = false diff --git a/roles/git/files/bin/workfy-repo.sh b/roles/git/files/bin/workfy-repo.sh new file mode 100755 index 0000000..fdcbf65 --- /dev/null +++ b/roles/git/files/bin/workfy-repo.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if git -C . rev-parse 2> /dev/null; then + remote_url=$(git remote -v | head -1 | sed 's/.*\t\(.*\) .*/\1/') + if [[ ${remote_url} != *"work.github.com"* ]]; then + git remote set-url origin "${remote_url//github.com/work.github.com}" + else + git remote set-url origin "${remote_url//work.github.com/github.com}" + fi + git remote -v +fi diff --git a/roles/git/tasks/main.yml b/roles/git/tasks/main.yml index 7e3ea4b..35599d9 100644 --- a/roles/git/tasks/main.yml +++ b/roles/git/tasks/main.yml @@ -57,3 +57,15 @@ path: "{{ home_folder }}/.bashrc" marker: "# {mark} git/files/functions.sh" block: "{{ lookup('file', 'files/functions.sh') }}" + +- name: Create ~/.bin/ folder + ansible.builtin.file: + path: "{{ home_folder }}/.bin/" + state: directory + mode: '755' + +- name: Copy scripts to ~/.bin + ansible.builtin.copy: + src: files/bin/workfy-repo.sh + dest: "{{ home_folder }}/.bin/workfy-repo" + mode: a+x diff --git a/tests/functional/roles/git/files/bin/test_workfy-repo.txt b/tests/functional/roles/git/files/bin/test_workfy-repo.txt new file mode 100644 index 0000000..be30edd --- /dev/null +++ b/tests/functional/roles/git/files/bin/test_workfy-repo.txt @@ -0,0 +1,25 @@ +$ rm -rf /repo 2> /dev/null +$ mkdir /repo +$ cd /repo && /code/roles/git/files/bin/workfy-repo.sh +$ cd /repo && git init +hint: Using 'master' as the name for the initial branch. This default branch name +hint: is subject to change. To configure the initial branch name to use in all +hint: of your new repositories, which will suppress this warning, call: +hint: +hint: git config --global init.defaultBranch +hint: +hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and +hint: 'development'. The just-created branch can be renamed via this command: +hint: +hint: git branch -m +Initialized empty Git repository in /repo/.git/ +$ cd /repo && git remote add origin git@github.com:deniscostadsc/dotfiles.git +$ cd /repo && git remote -v +origin git@github.com:deniscostadsc/dotfiles.git (fetch) +origin git@github.com:deniscostadsc/dotfiles.git (push) +$ cd /repo && /code/roles/git/files/bin/workfy-repo.sh +origin git@work.github.com:deniscostadsc/dotfiles.git (fetch) +origin git@work.github.com:deniscostadsc/dotfiles.git (push) +$ cd /repo && /code/roles/git/files/bin/workfy-repo.sh +origin git@github.com:deniscostadsc/dotfiles.git (fetch) +origin git@github.com:deniscostadsc/dotfiles.git (push)