@@ -14,7 +14,7 @@ function echo_version() {
1414}
1515
1616function remove_tracked_identities() {
17- git config --global --list |
17+ git config --global --list |
1818 grep -i " includeif\.gitdir:.*\.idm=${id} " |
1919 sed " s/\\ .idm=${id} \$ //" |
2020 sed ' s/^includeif/includeIf/' |
@@ -100,6 +100,8 @@ Command options:
100100 --name NAME - Name of the associated identity.
101101 --email EMAIL - Email of the associated identity.
102102 --key SSH_KEY - SSH private key of the associated identity.
103+ --signing-key SIGNING_KEY - (optional) add a gpg signing key.
104+ --sign-comits SIGN_COMMITS (optional) whether or not to sign commits.
103105 --ssh-command SSH_COMMAND - Customize the SSH command ignoring --key.
104106 list:
105107 Has no options.
@@ -232,6 +234,18 @@ while [[ $# -gt 0 ]]; do
232234 DIRECTORY=" ${2%/ } /"
233235 shift 2
234236 ;;
237+ --signing-key)
238+ if [ -z " $2 " ]; then
239+ echo ' ERROR: --signing-key must have a valid key following it.' >&2
240+ exit 1
241+ fi
242+ SIGNING_KEY=" $2 "
243+ shift 2
244+ ;;
245+ --sign-commits)
246+ SIGN_COMMITS=true
247+ shift
248+ ;;
235249 --tracked)
236250 LIST_TRACKED=true
237251 shift
@@ -263,6 +277,10 @@ case "${comm}" in
263277 SSH_COMMAND=" $( git config --global --get gitidm." ${ACTIVE_ID} " .sshCommand) "
264278 REAL_SSH_COMMAND=" $( git config --global --get core.sshCommand) "
265279 SSH_KEY=" $( git config --global --get gitidm." ${ACTIVE_ID} " .sshKey) "
280+ SIGNING_KEY=" $( git config --global --get gitidm." ${ACTIVE_ID} " .signingKey) "
281+ REAL_SIGNING_KEY=" $( git config --global --get user.signingkey) "
282+ SIGN_COMMITS=" $( git config --global --get gitidm." ${ACTIVE_ID} " .signCommits) "
283+ REAL_SIGN_COMMITS=" $( git config --global --get commit.gpgsign) "
266284 DISCREPENCY=false
267285 if [ -n " ${ACTIVE_ID} " ]; then
268286 git config --global --list | grep " ^gitidm\\ .${ACTIVE_ID} \\ ." | print_identities
@@ -279,6 +297,14 @@ case "${comm}" in
279297 echo " WARNING: core.sshCommand '${REAL_SSH_COMMAND} ' does not match the one used by the identity." >&2
280298 DISCREPENCY=true
281299 fi
300+ if [ ! " ${SIGNING_KEY} " = " ${REAL_SIGNING_KEY} " ]; then
301+ echo " WARNING: user.signingKey '${SIGNING_KEY} ' does not match the one used by the identity." >&2
302+ DISCREPENCY=true
303+ fi
304+ if [ ! " ${SIGN_COMMITS} " = " ${REAL_SIGN_COMMITS} " ]; then
305+ echo " WARNING: commit.gpgsign '${SIGN_COMMITS} ' does not match the one used by the identity." >&2
306+ DISCREPENCY=true
307+ fi
282308 if [ " ${DISCREPENCY} " = true ]; then
283309 echo " ERROR: found above discrepencies with identity. To fix run 'git idm use ${ACTIVE_ID} '." >&2
284310 exit 1
@@ -313,6 +339,12 @@ case "${comm}" in
313339 if [ -n " ${SSH_COMMAND} " ]; then
314340 git config --global gitidm." ${id} " .sshCommand " ${SSH_COMMAND} "
315341 fi
342+ if [ -n " ${SIGNING_KEY} " ]; then
343+ git config --global gitidm." ${id} " .signingKey " ${SIGNING_KEY} "
344+ fi
345+ if [ -n " ${SIGN_COMMITS} " ]; then
346+ git config --global gitidm." ${id} " .signCommits " ${SIGN_COMMITS} "
347+ fi
316348 ;;
317349 help)
318350 usage
@@ -353,6 +385,8 @@ case "${comm}" in
353385 NAME=" $( git config --global --get gitidm." ${id} " .name) "
354386 EMAIL=" $( git config --global --get gitidm." ${id} " .email) "
355387 SSH_COMMAND=" $( git config --global --get gitidm." ${id} " .sshCommand) "
388+ SIGNING_KEY=" $( git config --global --get gitidm." ${id} " .signingKey) "
389+ SIGN_COMMITS=" $( git config --global --get gitidm." ${id} " .signCommits) "
356390 if [ -n " ${NAME} " ]; then
357391 run_command git config --file ~ /" .gitconfig_idm_${id} " user.name " ${NAME} "
358392 fi
@@ -362,6 +396,12 @@ case "${comm}" in
362396 if [ -n " ${SSH_COMMAND} " ]; then
363397 run_command git config --file ~ /" .gitconfig_idm_${id} " core.sshCommand " ${SSH_COMMAND} "
364398 fi
399+ if [ -n " ${SIGNING_KEY} " ]; then
400+ run_command git config --file ~ /" .gitconfig_idm_${id} " user.signingkey " ${SIGNING_KEY} "
401+ fi
402+ if [ -n " ${SIGN_COMMITS} " ]; then
403+ run_command git config --file ~ /" .gitconfig_idm_${id} " commit.gpgsign " ${SIGN_COMMITS} "
404+ fi
365405 run_command git config --global includeIf." gitdir:${DIRECTORY} " .idm " ${id} "
366406 run_command git config --global includeIf." gitdir:${DIRECTORY} " .path ~ /" .gitconfig_idm_${id} "
367407 ;;
@@ -382,6 +422,8 @@ case "${comm}" in
382422 EMAIL=" $( git config --global --get gitidm." ${id} " .email) "
383423 SSH_COMMAND=" $( git config --global --get gitidm." ${id} " .sshCommand) "
384424 SSH_KEY=" $( git config --global --get gitidm." ${id} " .sshKey) "
425+ SIGNING_KEY=" $( git config --global --get gitidm." ${id} " .signingKey) "
426+ SIGN_COMMITS=" $( git config --global --get gitidm." ${id} " .signCommits) "
385427 if [ -n " ${NAME} " ]; then
386428 run_command git config --global user.name " ${NAME} "
387429 fi
@@ -391,6 +433,18 @@ case "${comm}" in
391433 if [ -n " ${SSH_COMMAND} " ]; then
392434 run_command git config --global core.sshCommand " ${SSH_COMMAND} "
393435 fi
436+ if [ -n " ${SIGNING_KEY} " ];
437+ then
438+ run_command git config --global user.signingkey " ${SIGNING_KEY} "
439+ else
440+ run_command git config --global --unset user.signingkey
441+ fi
442+ if [ -n " ${SIGN_COMMITS} " ];
443+ then
444+ run_command git config --global commit.gpgsign " ${SIGN_COMMITS} "
445+ else
446+ run_command git config --global --unset commit.gpgsign
447+ fi
394448 run_command git config --global user.activeidm " ${id} "
395449 if [ -n " ${SSH_KEY} " ]; then
396450 check_ssh_agent " ${SSH_KEY} "
0 commit comments