Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FIXME: The test that comes with this fails, I can't get the created t…

…ags to have the specified author/email

Support reading GIT_AUTHOR_{NAME,EMAIL} env variables

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...
commit 61e00540d41497ff5b9e40c9dd4a7d240d91737d 1 parent ac97025
@avar avar authored
Showing with 49 additions and 9 deletions.
  1. +13 −5 bin/git-deploy
  2. +5 −0 lib/Git/Deploy.pm
  3. +31 −4 t/run.t
View
18 bin/git-deploy
@@ -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' ) {
@@ -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) {
@@ -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:
View
5 lib/Git/Deploy.pm
@@ -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
@@ -251,6 +253,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", "") }
+
}
View
35 t/run.t
@@ -9,10 +9,37 @@ git_deploy_test(
"A rollout etc.",
sub {
my $ctx = shift;
- _run_git_deploy(
- $ctx,
- args => "start",
- );
+
+ # First test that the user.{email,name} warnings work properly
+ {
+ local $ENV{GIT_AUTHOR_NAME} = '';
+ local $ENV{GIT_AUTHOR_EMAIL} = '';
+ _system qq[git config user.$_ ""] for qw(name email);
+ _run_git_deploy(
+ $ctx,
+ args => "start",
+ wanted_exit_code => -1, # -1 = any non-zero OK
+ );
+ like(
+ `cat $ctx->{last_stderr}`,
+ qr/Please make sure you set your Git user name & E-Mail/,
+ "We should whine about an unset user name & E-Mail"
+ );
+
+ # We should support
+ local $ENV{GIT_AUTHOR_NAME} = 'Git Deploy AUTHOR_NAME Test';
+ local $ENV{GIT_AUTHOR_EMAIL} = 'git-deploy_AUTHOR_EMAIL-test@example.com';
+ _run_git_deploy(
+ $ctx,
+ args => "start",
+ );
+ chomp(my $tag_created_on_start_due_to_no_tag_existing = qx[git tag -l]);
+ chomp(my $tag_info = qx[git show $tag_created_on_start_due_to_no_tag_existing]);
+ like($tag_info, qr/\Q$ENV{GIT_AUTHOR_NAME}\E/, "We should have created a tag with $ENV{GIT_AUTHOR_NAME} as the author");
+ like($tag_info, qr/\Q$ENV{GIT_AUTHOR_EMAIL}\E/, "We should have created a tag with $ENV{GIT_AUTHOR_EMAIL} as the author");
+ _system "git config --remove-section user";
+ }
+
like(`git tag -l`, qr/debug/, "We created a tag because there wasn't one already");
like(`cat $ctx->{last_stderr}`, qr/Deploy procedure has started/, "We print a notice about the deploy being started");
like(`cat $ctx->{last_stderr}`, qr/Not sending mail on action/, "By default we don't send mail on 'start'");
Please sign in to comment.
Something went wrong with that request. Please try again.