dspinellis / git-issue

Git-based decentralized issue management
GNU General Public License v3.0
776 stars 66 forks source link

init breaks when no global user.name and/or user.email are set #94

Closed hansalves closed 2 years ago

hansalves commented 2 years ago

I use separate email addresses for work and private projects. I have no user.email in my global git config so I won't forget to set the right email for new projects/clones.

This causes git issue init to fail with

$> gi init

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'halves@angua.(none)')
fatal: ambiguous argument '': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Operation aborted

It also causes most testcases to fail.

For now I have fixed this on my machine with the following patch

diff --git a/git-issue.sh b/git-issue.sh
index e75af83..12fb5e1 100755
--- a/git-issue.sh
+++ b/git-issue.sh
@@ -222,7 +222,7 @@ USAGE_new_EOF

 sub_init()
 {
-  local existing
+  local existing username useremail

   while getopts e flag ; do
     case $flag in
@@ -238,6 +238,8 @@ sub_init()

   test -d .issues && error 'An .issues directory is already present'
   mkdir .issues || error 'Unable to create .issues directory'
+  username=`git config --local user.name`
+  useremail=`git config --local user.email`
   cdissues
   if ! [ "$existing" ] ; then
     git init -q || error 'Unable to initialize Git directory'
@@ -273,6 +275,12 @@ This is an distributed issue tracking repository based on Git.
 Visit [git-issue](https://github.com/dspinellis/git-issue) for more information.
 EOF
   git add config README.md templates/comment templates/description
+  if [ -n "$username" ] ; then
+    git config --local user.name "$username"
+  fi
+  if [ -n "$useremail" ] ; then
+    git config --local user.email "$useremail"
+  fi
   commit 'gi: Initialize issues repository' 'gi init'
   echo "Initialized empty issues repository in $(pwd)"
 }

However, this only works in case you are working from another git repository with a local configuration so I'm not sure that's the best solution.

dspinellis commented 2 years ago

So if a local configuration exists, it is propagated to the newly developed repo. This is a reasonable addition. If there is not way to obtain these, then gi will rightly exit after git init reports its error.

hansalves commented 2 years ago

I created a pull request https://github.com/dspinellis/git-issue/pull/95

dspinellis commented 2 years ago

I merged it; thanks!