Commit 545f5fad by Richard Earnshaw

contrib: Check and if needed set user.name and user.email in gcc-git-customization.sh

As discussed on IRC, this adds a couple more checks in the
customization setup for git.  If the variables user.name and
user.email are not set anywhere in the git config hierarchy, we set
some local values.  We always ask about the values we detect and if
the user gives an answer that is new, we save that in the local
config: this gives the opportunity to use different values to those
configured for the global space.

Also cleaned up a couple of minor niggles, such as using $(cmd) rather
than `cmd` for subshells and some quoting issues when using eval.

	* gcc-git-customization.sh: Check that user.name and user.email
	are set.  Use $(cmd) instead of `cmd`.  Fix variable quoting when
	using eval.
parent 1c2755a6
2020-01-16 Richard Earnshaw <rearnsha@arm.com>
* gcc-git-customization.sh: Check that user.name and user.email
are set. Use $(cmd) instead of `cmd`. Fix variable quoting when
using eval.
2020-01-16 Jakub Jelinek <jakub@redhat.com> 2020-01-16 Jakub Jelinek <jakub@redhat.com>
* gcc-git-customization.sh: Verify the id to be printed is ancestor of * gcc-git-customization.sh: Verify the id to be printed is ancestor of
......
...@@ -11,9 +11,9 @@ ask () { ...@@ -11,9 +11,9 @@ ask () {
read answer read answer
if [ "x$answer" = "x" ] if [ "x$answer" = "x" ]
then then
eval $var=$default eval $var=\"$default\"
else else
eval $var=$answer eval $var=\"$answer\"
fi fi
} }
...@@ -30,7 +30,52 @@ git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream) ...@@ -30,7 +30,52 @@ git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream)
# *.md diff=md # *.md diff=md
git config diff.md.xfuncname '^\(define.*$' git config diff.md.xfuncname '^\(define.*$'
upstream=`git config --get "gcc-config.upstream"` set_user=$(git config --get "user.name")
set_email=$(git config --get "user.email")
if [ "x$set_user" = "x" ]
then
# Try to guess the user's name by looking it up in the password file
new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }')
if [ "x$new_user" = "x" ]
then
new_user="(no default)"
fi
else
new_user=$set_user
fi
ask "Your name" "${new_user}" new_user
if [ "x$new_user" = "x(no default)" ]
then
echo "Cannot continue, git needs to record your name against commits"
exit 1
fi
if [ "x$set_email" = "x" ]
then
new_email="(no_default)"
else
new_email=$set_email
fi
ask "Your email address (for git commits)" "${new_email}" new_email
if [ "x$new_email" = "x(no default)" ]
then
echo "Cannot continue, git needs to record your email address against commits"
exit 1
fi
if [ "x$set_user" != "x$new_user" ]
then
git config "user.name" "$new_user"
fi
if [ "x$set_email" != "x$new_email" ]
then
git config "user.email" "$new_email"
fi
upstream=$(git config --get "gcc-config.upstream")
if [ "x$upstream" = "x" ] if [ "x$upstream" = "x" ]
then then
upstream="origin" upstream="origin"
...@@ -38,27 +83,27 @@ fi ...@@ -38,27 +83,27 @@ fi
ask "Local name for upstream repository" "origin" upstream ask "Local name for upstream repository" "origin" upstream
git config "gcc-config.upstream" "$upstream" git config "gcc-config.upstream" "$upstream"
remote_id=`git config --get "gcc-config.user"` remote_id=$(git config --get "gcc-config.user")
if [ "x$remote_id" = "x" ] if [ "x$remote_id" = "x" ]
then then
# See if the url specifies the remote user name. # See if the url specifies the remote user name.
url=`git config --get "remote.$upstream.url"` url=$(git config --get "remote.$upstream.url")
if [ "x$url" = "x" ] if [ "x$url" = "x" ]
then then
# This is a pure guess, but for many people it might be OK. # This is a pure guess, but for many people it might be OK.
remote_id=`whoami` remote_id=$(whoami)
else else
remote_id=`echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|"` remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
if [ x$remote_id = x$url ] if [ x$remote_id = x$url ]
then then
remote_id=`whoami` remote_id=$(whoami)
fi fi
fi fi
fi fi
ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
git config "gcc-config.user" "$remote_id" git config "gcc-config.user" "$remote_id"
old_pfx=`git config --get "gcc-config.userpfx"` old_pfx=$(git config --get "gcc-config.userpfx")
if [ "x$old_pfx" = "x" ] if [ "x$old_pfx" = "x" ]
then then
old_pfx="me" old_pfx="me"
...@@ -72,7 +117,7 @@ echo "Setting up tracking for personal namespace $remote_id in remotes/$upstream ...@@ -72,7 +117,7 @@ echo "Setting up tracking for personal namespace $remote_id in remotes/$upstream
git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/${new_pfx}/*" ":refs/remotes/${upstream}/${old_pfx}/" git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/${new_pfx}/*" ":refs/remotes/${upstream}/${old_pfx}/"
git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/" git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/"
push_rule=`git config --get "remote.${upstream}.push"` push_rule=$(git config --get "remote.${upstream}.push")
if [ "x$push_rule" != "x" ] if [ "x$push_rule" != "x" ]
then then
echo "***********************************************" echo "***********************************************"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment