Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why set email and user.name for every repository? #105

Open
lechner opened this issue Aug 27, 2018 · 6 comments
Open

Why set email and user.name for every repository? #105

lechner opened this issue Aug 27, 2018 · 6 comments

Comments

@lechner
Copy link

lechner commented Aug 27, 2018

Hi, should user.name and email really be added to every repository? I have both in my ~/.gitconfig? An alternative could be to warn if neither is available, and maybe add them (preferably globally) fromDEB_FULLNAME and DEB_EMAIL.

I stumbled on the issue because of a bug in golang-github-tcnksm-go-gitconfig, where tests were not properly isolated. (That merge request is here.) While this issue is not necessarily a bug, it may make it more difficult to change an email. Please let me know your favorite way to resolve, and I will submit a merge request. Thank you!

dh-make-golang/make.go

Lines 296 to 306 in f0afc0f

if debianName := getDebianName(); debianName != "TODO" {
if err := runGitCommandIn(dir, "config", "user.name", debianName); err != nil {
return dir, err
}
}
if debianEmail := getDebianEmail(); debianEmail != "TODO" {
if err := runGitCommandIn(dir, "config", "user.email", debianEmail); err != nil {
return dir, err
}
}

@stapelberg
Copy link
Collaborator

I have a different user/email in my global git config, so setting the debian ones for debian repositories only makes sense in my world.

I would accept a patch which skips this behavior when the global git config already contains the correct name, though :)

@lechner
Copy link
Author

lechner commented Aug 27, 2018

Great! Would you mind if I use golang-github-tcnksm-go-gitconfig, which I recently got to know quite well? It is a prerequisite for git-lab and will probably be around for a while. Thank you!

@stapelberg
Copy link
Collaborator

Isn’t shelling out to the git tool sufficient for this?

@lechner
Copy link
Author

lechner commented Aug 27, 2018

Doing it by hand will add this code. It is totally your call. Thank you!

func execGitConfig(args ...string) (string, error) {
	gitArgs := append([]string{"config", "--get", "--null"}, args...)
	var stdout bytes.Buffer
	cmd := exec.Command("git", gitArgs...)
	cmd.Stdout = &stdout
	cmd.Stderr = ioutil.Discard

	err := cmd.Run()
	if exitError, ok := err.(*exec.ExitError); ok {
		if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
			if waitStatus.ExitStatus() == 1 {
				return "", &ErrNotFound{Key: args[len(args)-1]}
			}
		}
		return "", err
	}

	return strings.TrimRight(stdout.String(), "\000"), nil
}

@stapelberg
Copy link
Collaborator

Yeah, I think I’d prefer that code (modulo some comments which we can discuss over a pull request) over an additional dependency :)

@lechner
Copy link
Author

lechner commented Aug 27, 2018

#106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants