From 54f54317abb1229ef0b5ac39a9a1d178f786ca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Jim=C3=A9nez=20Hern=C3=A1ndez?= <27415403+HugoJH@users.noreply.github.com> Date: Thu, 27 Jan 2022 23:08:01 +0100 Subject: [PATCH 1/3] Added configuration of gpg indentity --- .git-clone-init | 4 ++-- post-checkout | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.git-clone-init b/.git-clone-init index 4cae6b7..06dd361 100644 --- a/.git-clone-init +++ b/.git-clone-init @@ -1,6 +1,6 @@ #!/bin/bash case "$url" in - *@github.com:* ) email=""; name="";; - *//github.com/* ) email=""; name="";; + *@github.com:* ) email=""; name=""; gpgid="";; + *//github.com/* ) email=""; name=""; gpgid="";; esac diff --git a/post-checkout b/post-checkout index 27e6557..8a0b945 100755 --- a/post-checkout +++ b/post-checkout @@ -33,8 +33,8 @@ cat << INPUT > ~/.git-clone-init #!/bin/bash case "\$url" in - *@github.com:* ) email=""; name="";; - *//github.com/* ) email=""; name="";; + *@github.com:* ) email=""; name=""; gpgid="";; + *//github.com/* ) email=""; name=""; gpgid="";; esac INPUT warn "\nMissing file ~/.git-clone-init. Template created..." @@ -51,3 +51,10 @@ git config --local user.email "$email" git config --local user.name "$name" echo -e "\nLocal identity for ${PWD##*/} set to \"$name <$email>\"" + +if [[ ! -z $gpgid ]]; then + git config commit.gpgsign true + git config user.signingkey $gpgid + + echo -e "\n Repo configured to use $gpgid GPG Identity" +fi From 54fcc0a8e8ad6ea91a02ebae780669c6866b89d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Jim=C3=A9nez=20Hern=C3=A1ndez?= <27415403+HugoJH@users.noreply.github.com> Date: Thu, 27 Jan 2022 22:57:25 +0100 Subject: [PATCH 2/3] Fixed README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 33aacff..6e3fe64 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Screenshot of a git clone](/about.png) -Whenever a repository is cloned, author information (user.email, user.name) is set according defined patterns. No longer pushing commits with your corporate email address by accident. +Whenever a repository is cloned, author information (user.email, user.name, user.signingkey) is set according defined patterns. No longer pushing commits with your corporate email address by accident. ## Installation @@ -28,10 +28,10 @@ You can use the file ".git-clone-init" as a starting point. Keep in mind to crea Example: ```bash case "$url" in - *@github.com:* ) email="my-public@email"; name="public name";; - *//github.com/* ) email="my-public@email"; name="public name";; - *@corp.com:* ) email="my-corporate@email"; name="real name";; - *//corp.com/* ) email="my-corporate@email"; name="real name";; + *@github.com:* ) email="my-public@email"; name="public name"; gpgid="GPG ID";; + *//github.com/* ) email="my-public@email"; name="public name"; gpgid="GPG ID";; + *@corp.com:* ) email="my-corporate@email"; name="real name"; gpgid="GPG same/other ID";; + *//corp.com/* ) email="my-corporate@email"; name="real name"; gpgid="GPG same/other ID";; esac ``` From dbe20ab0cd36ce6b46582fa546b62ba74f650e6a Mon Sep 17 00:00:00 2001 From: DrVanScott Date: Wed, 12 Jun 2024 18:45:31 +0200 Subject: [PATCH 3/3] Make signing functionality optional --- README.md | 10 +++++----- git-clone-init | 8 ++++++-- post-checkout | 17 +++++++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 08e1986..ed76605 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![Screenshot of a git clone](/about.png) Whenever a repository is cloned, author information (`user.email`, `user.name`) is set according defined patterns. No longer pushing commits with your corporate email address by accident. -Optionally, also `user.signingkey` can be configured. +Optionally, also `user.signingkey` and `commit.gpgsign` can be configured independently. Corresponding variablels `gpgid` and `gpgsign` might be set or omitted. ## Installation @@ -29,10 +29,10 @@ You can use the file `git-clone-init` as a starting point. Keep in mind to creat Example: ```bash case "$url" in - *@github.com:* ) email="my-public@email"; name="public name"; gpgid="GPG ID";; - *//github.com/* ) email="my-public@email"; name="public name"; gpgid="GPG ID";; - *@corp.com:* ) email="my-corporate@email"; name="real name"; gpgid="GPG same/other ID";; - *//corp.com/* ) email="my-corporate@email"; name="real name"; gpgid="GPG same/other ID";; + *@github.com:* ) email="my-public@email"; name="public name";; + *//github.com/* ) email="my-public@email"; name="public name";; + *@corp.com:* ) email="my-corporate@email"; name="real name"; gpgid="GPG ID"; gpgsign="true/false";; + *//corp.com/* ) email="my-corporate@email"; name="real name"; gpgid="GPG ID"; gpgsign="true/false";; esac ``` diff --git a/git-clone-init b/git-clone-init index 06dd361..99093f0 100644 --- a/git-clone-init +++ b/git-clone-init @@ -1,6 +1,10 @@ #!/bin/bash +#You can also provide the following variables: +# gpgid ID of an gpg key configuration of user.signingkey +# gpgsign true/false configuration of commit.gpgsign + case "$url" in - *@github.com:* ) email=""; name=""; gpgid="";; - *//github.com/* ) email=""; name=""; gpgid="";; + *@github.com:* ) email=""; name="";; + *//github.com/* ) email=""; name="";; esac diff --git a/post-checkout b/post-checkout index f681da9..69cb65e 100755 --- a/post-checkout +++ b/post-checkout @@ -33,9 +33,13 @@ if [[ ! -f "$configpath" ]]; then cat << INPUT > "$configpath" #!/bin/bash +#You can also provide the following variables: +# gpgid ID of an gpg key configuration of user.signingkey +# gpgsign true/false configuration of commit.gpgsign + case "\$url" in - *@github.com:* ) email=""; name=""; gpgid="";; - *//github.com/* ) email=""; name=""; gpgid="";; + *@github.com:* ) email=""; name="";; + *//github.com/* ) email=""; name="";; esac INPUT warn "\nMissing file $configpath. Template created..." @@ -54,8 +58,13 @@ git config --local user.name "$name" echo -e "\nLocal identity for ${PWD##*/} set to \"$name <$email>\"" if [[ ! -z $gpgid ]]; then - git config commit.gpgsign true - git config user.signingkey $gpgid + git config user.signingkey "$gpgid" echo -e "\n Repo configured to use $gpgid GPG Identity" fi + +if [[ ! -z $gpgsign ]]; then + git config commit.gpgsign "$gpgsign" + + echo -e "\n Repo configured to use commit.gpgsign=$gpgsign" +fi