Skip to content

Commit

Permalink
Release 0.11 Bugfix on git setup
Browse files Browse the repository at this point in the history
When setting up Git for the first time an out of order configuration can
cause issues for the user.

fixes #6
  • Loading branch information
samrocketman committed Jun 5, 2024
1 parent 41af511 commit a598aec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# git-idm v0.11

- Bug fix: since initial setup assumes a certain order of `.gitconfig` sections,
then attempt to assure initial setup every time a write operation would occur
to `.gitconfig`. See issue [#6][#6].

[#6]: https://github.com/samrocketman/git-identity-manager/issues/6

# git-idm v0.10

Important Notes:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ attempts to make it less painful.

# Requirements

- Git 2.13 or later.
- Git 2.18 or later.
- [`git 2.10` or later because of `core.sshCommand`][git-2.10].
- [`git 2.13` or later because of `includeIf.<condition>.path`][git-2.13].
- [`git 2.18` or later because of git-config bug][git-2.18].
- GNU bash
- awk (BSD or GNU awk recommended)
- sed (BSD or GNU sed recommended)
Expand Down Expand Up @@ -94,4 +95,5 @@ Verify the identity has switched with `git config user.email`.
[build-status]: https://travis-ci.org/samrocketman/git-identity-manager
[git-2.10]: https://github.com/git/git/blob/v2.10.0/Documentation/RelNotes/2.10.0.txt#L83-L84
[git-2.13]: https://github.com/git/git/blob/v2.13.0/Documentation/RelNotes/2.13.0.txt#L127-L130
[git-2.18]: https://github.com/git/git/blob/53f9a3e157dbbc901a02ac2c73346d375e24978c/Documentation/RelNotes/2.18.0.txt#L379-L384
[pbs]: https://www.pbs.org/newshour/health/back-pain-industry-taking-patients-unhealthy-ride
22 changes: 19 additions & 3 deletions git-idm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
#License: MIT
#Project URL: https://github.com/samrocketman/git-identity-manager

version='0.10'
version='0.11'

if ! git --version | awk 'BEGIN { FS="." }; $2 < 13 { exit(1) }'; then
echo 'WARNING: "git --version" is older than Git 2.13. git-idm will have unexpected behavior.' >&2
if ! git --version | awk 'BEGIN { FS="." }; $2 < 18 { exit(1) }'; then
echo 'WARNING: "git --version" is older than Git 2.18. git-idm will have unexpected behavior.' >&2
fi

function initial_setup() {
if [ ! -f ~/.gitconfig ]; then
touch ~/.gitconfig
fi
if ! { git config --global -l | grep '^user\.' || grep -F '[user]' ~/.gitconfig; } > /dev/null; then
echo '[user]' >> ~/.gitconfig
fi
if ! { git config --global -l | grep '^include\.' || grep -F '[include]' ~/.gitconfig; } > /dev/null; then
echo '[include]' >> ~/.gitconfig
fi
}

function echo_version() {
echo "git idm v${version}" >&2
}
Expand Down Expand Up @@ -421,6 +433,7 @@ EOF
echo 'ERROR: options --name, --email, and --key or --ssh-command are required when adding an identity for the first time.' >&2
exit 1
fi
initial_setup
if [ -n "${NAME}" ]; then
run_command git config --global gitidm."${id}".name "${NAME}"
fi
Expand All @@ -444,6 +457,7 @@ EOF
no_ssh_key_warning "${id}"
;;
copy-key-to)
initial_setup
SSH_KEY="$(git config --global --get gitidm."${FROM_ID}".sshKey)"
SSH_COMMAND="$(git config --global --get gitidm."${FROM_ID}".sshCommand)"
if [ -z "${SSH_KEY:-}" ] || [ -z "${SSH_COMMAND:-}" ]; then
Expand Down Expand Up @@ -490,6 +504,7 @@ EOF
echo 'ERROR: git idm track <identity> --directory <directory> requires --directory option to be passed. See "git idm help".' >&2
exit 1
fi
initial_setup
add_identity_file "${id}"
run_command git config --global includeIf."gitdir:${DIRECTORY}".idm "${id}"
run_command git config --global includeIf."gitdir:${DIRECTORY}".path ~/".gitconfig_idm_${id}"
Expand All @@ -508,6 +523,7 @@ EOF
echo "ERROR: Identity ${id} does not exist. See 'git idm list' or 'git idm help'." >&2
exit 1
fi
initial_setup
NAME="$(git config --global --get gitidm."${id}".name)"
EMAIL="$(git config --global --get gitidm."${id}".email)"
if [ -n "${NAME}" ]; then
Expand Down

0 comments on commit a598aec

Please sign in to comment.