Skip to content

Commit

Permalink
Support reading GIT_AUTHOR_{NAME,EMAIL} env variables
Browse files Browse the repository at this point in the history
Change the discovery of the user.name and user.email variables to
first look up the user/name in the GIT_AUTHOR_NAME and
GIT_AUTHOR_EMAIL environment variables. This mirrors the behavior of
Git itself, see git-commit-tree(1) for details.

The reason to do this is that managing your Git identity via these
variables can be more conveniente than setting them in a config file,
it makes it easier to set them differently on different hosts.

Also change the error message we display if these aren't set, we'll
now error out with something like this when we can't get an author
name or an E-Mail;

    $ perl -Ilib bin/git-deploy start
    # FATAL: Please make sure you set your Git user name & E-Mail
    # FATAL: before using this tool, i.e. either run:
    # FATAL:
    # FATAL:     git config --global user.name 'Your Name'
    # FATAL:     git config --global user.email 'email@host.com'
    # FATAL:
    # FATAL: Or make sure the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL
    # FATAL: environment variables are appropriately set.

This patch is inspired by Rob's
#20, I thought it made
more sense to introduce a function for looking up the user name &
E-Mail rather than hooking into the low-level config mechanism. This
also adjusts our documentation to indicate to users that they can use
this instead of setting user.{name,email}.
  • Loading branch information
avar committed Sep 1, 2012
1 parent 4abc345 commit dc4541f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 13 additions & 5 deletions bin/git-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ sub send_email_with_sendmail {

my $handle;
my $sendmail= get_config("mail-tool","/usr/sbin/sendmail -f");
my $from_name= get_config("user.name");
my $from_email= get_config("user.email");
my $from_name= get_user_name();
my $from_email= get_user_email();

my $cmd= "$sendmail '$from_email' '$to_mail'";
if ( $to_mail eq 'debug' ) {
Expand Down Expand Up @@ -641,12 +641,14 @@ if ( $list || $show_tag ) {
exit(0);
}

if (!$force and (!get_config("user.name","") or !get_config("user.email",""))) {
_die "Please make sure you execute:\n\n"
if (!$force and (!get_user_name() or !get_user_email())) {
_die "Please make sure you set your Git user name & E-Mail\n"
. "before using this tool, i.e. either run:\n\n"
. " git config --global user.name 'Your Name'\n"
. " git config --global user.email 'email\@host.com'\n"
. "\n"
. "before you use this tool";
. "Or make sure the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL\n"
. "environment variables are appropriately set.";
}

if ($check_clean) {
Expand Down Expand Up @@ -1637,8 +1639,14 @@ L<git-config(1)> for details:
=item * user.name
You can also make sure C<GIT_AUTHOR_NAME> is set. See
L<git-commit-tree(1)> for details.
=item * user.email
You can also make sure C<GIT_AUTHOR_EMAIL> is set. See
L<git-commit-tree(1)> for details.
=back
And these are L<git-deploy(1)>-specific options:
Expand Down
5 changes: 5 additions & 0 deletions lib/Git/Deploy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ our @EXPORT= qw(
get_config_int
get_config_path
get_config_bool
get_user_name
get_user_email
get_current_branch
get_deploy_file_name
get_ref_info
Expand Down Expand Up @@ -247,6 +249,9 @@ sub get_config_path { return _get_config("--path",@_) }
sub get_config_int { return _get_config("--int",@_) }
sub get_config_bool { return 'true' eq _get_config("--bool",@_) }

sub get_user_name { return $ENV{GIT_AUTHOR_NAME} || get_config("user.name", "") }
sub get_user_email { return $ENV{GIT_AUTHOR_EMAIL} || get_config("user.email", "") }

}


Expand Down

1 comment on commit dc4541f

@demerphq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you think this is necessary then fine.

On the other hand I feel like when doing a rollout it may be desirable to control the user name used, etc.

How could we make this check redundant in the face of something like ldapmebaby.pl?

Please sign in to comment.