Skip to content

Commit

Permalink
Merge 5060d20 into a5eb2ee
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesg committed Oct 24, 2014
2 parents a5eb2ee + 5060d20 commit a1f0ff4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 33 deletions.
14 changes: 12 additions & 2 deletions Raw.xs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ typedef git_raw_repository * Repository;
typedef struct {
git_push *push;
git_raw_push_callbacks callbacks;
int success;
} git_raw_push;

typedef git_raw_push * Push;
Expand Down Expand Up @@ -1332,8 +1333,17 @@ STATIC int git_packbuilder_progress_cbb(int stage, unsigned int current, unsigne
return 0;
}

STATIC int git_push_status_cbb(const char *ref, const char *msg, void *cbs) {
STATIC int git_push_status_cbb(const char *ref, const char *msg, void *p) {
dSP;
Push push = (Push) p;
SV *cb = push -> callbacks.status;

if (msg != NULL) {
push -> success = 0;
}

if (!cb)
return 0;

ENTER;
SAVETMPS;
Expand All @@ -1343,7 +1353,7 @@ STATIC int git_push_status_cbb(const char *ref, const char *msg, void *cbs) {
mXPUSHs(newSVpv(msg, 0));
PUTBACK;

call_sv(((git_raw_push_callbacks *) cbs) -> status, G_DISCARD);
call_sv(cb, G_VOID);

SPAGAIN;

Expand Down
17 changes: 10 additions & 7 deletions lib/Git/Raw/Push.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ Git::Raw::Push - Git push class
});
# perform the actual push
$push -> finish;
if ($push -> unpack_ok) {
print "References updated successfully", "\n";
if ($push -> finish) {
if ($push -> unpack_ok) {
print "References updated successfully", "\n";
} else {
print STDERR "Not all references updated", "\n";
}
$push -> update_tips;
} else {
print STDERR "Not all references updated", "\n";
print STDERR "Push failed", "\n";
}
$push -> update_tips;
# disconnect the remote
$remote -> disconnect;
Expand Down Expand Up @@ -111,7 +113,8 @@ C<$msg> is defined, the reference mentioned in C<$ref> has not been updated.
=head2 finish( )
Perform the actual push.
Perform the actual push. Return a truthy value to indicate if the push was
successful.
=head2 unpack_ok( )
Expand Down
74 changes: 54 additions & 20 deletions t/19-push.t
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $push -> callbacks({
});

$total_packed = 0;
$push -> finish;
is $push -> finish, 1;
is $push -> unpack_ok, 1;
ok ($total_packed > 0);
is $updated_ref, "refs/heads/master";
Expand Down Expand Up @@ -174,6 +174,8 @@ is scalar(@remotes), 1;
$remote = shift @remotes;

my ($credentials_fired, $sideband_fired, $update_tips_fired) = (0, 0, 0);
my ($pack_progress_fired, $transfer_progress_fired, $status_fired) = (0, 0, 0);

$remote -> callbacks({
'credentials' => sub {
$credentials_fired = 1;
Expand All @@ -182,26 +184,14 @@ $remote -> callbacks({
'sideband_progress' => sub {
my ($msg) = @_;

like $msg, qr/pre-receive hook/;
is $msg, "This is from the pre-receive hook!";
$sideband_fired = 1;
},
'update_tips' => sub {
my ($ref, $a, $b) = @_;

is $ref, 'refs/remotes/origin/ssh_branch';
ok !defined($a);
ok defined($b);
isnt $a, $b;
$update_tips_fired = 1;
}
});

$remote -> connect('push');

$push = Git::Raw::Push -> new($remote);
$push -> add_refspec("refs/heads/ssh_branch:");

my ($pack_progress_fired, $transfer_progress_fired, $status_fired) = (0, 0, 0);
$push -> callbacks({
'pack_progress' => sub {
my ($stage, $current, $total) = @_;
Expand All @@ -217,19 +207,20 @@ $push -> callbacks({
my ($ref, $msg) = @_;

is $ref, 'refs/heads/ssh_branch';
ok !defined($msg);
ok defined($msg);
like $msg, qr/pre-receive hook/;
$status_fired = 1;
}
});

# setup a pre-receive hook that just print out a message
# setup a pre-receive hook that fails
my $pre_receive_content = <<'EOS';
#!/usr/bin/env perl
$|++;
print STDERR "This is from the pre-receive hook!";
exit(0);
exit(1);
EOS

my $pre_receive_file = File::Spec->catfile ($remote_path, '.git', 'hooks', 'pre-receive');
Expand All @@ -241,16 +232,59 @@ write_file($pre_receive_file, $pre_receive_content);
ok -e $pre_receive_file;
chmod 0755, $pre_receive_file;

$push -> finish;
is $push -> unpack_ok, 1;

# pre-receive hook kick
is $push -> finish, 0;
is $sideband_fired, 1;
is $credentials_fired, 1;
is $pack_progress_fired, 1;
is $transfer_progress_fired, 1;
is $status_fired, 1;

$remote -> disconnect;
$remote -> connect('push');

# setup a pre-receive hook that succeeds
$pre_receive_content = <<'EOS';
#!/usr/bin/env perl
$|++;
print STDERR "This is from the pre-receive hook!";
exit(0);
EOS

write_file($pre_receive_file, $pre_receive_content);

$remote -> callbacks({
'update_tips' => sub {
my ($ref, $a, $b) = @_;

is $ref, 'refs/remotes/origin/ssh_branch';
ok !defined($a);
ok defined($b);
isnt $a, $b;
$update_tips_fired = 1;
}
});

$push = Git::Raw::Push -> new($remote);
$push -> add_refspec("refs/heads/ssh_branch:");
$push -> callbacks({
'status' => sub {
my ($ref, $msg) = @_;

is $ref, 'refs/heads/ssh_branch';
ok !defined($msg);
$status_fired = 1;
}
});

$status_fired = 0;
is $push -> finish, 1;
is $push -> unpack_ok, 1;
is $status_fired, 1;
is $update_tips_fired, 0;

$push -> update_tips;
is $update_tips_fired, 1;

Expand Down
20 changes: 16 additions & 4 deletions xs/Push.xs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ new(class, remote)
rc = git_push_new(&p, r -> remote);
git_check_error(rc);

Newx(push, 1, git_raw_push);
Newxz(push, 1, git_raw_push);
git_init_push_callbacks(&push -> callbacks);
push -> push = p;

Expand All @@ -41,25 +41,33 @@ add_refspec(self, refspec)
rc = git_push_add_refspec(self -> push, SvPVbyte_nolen(refspec));
git_check_error(rc);

void
SV *
finish(self)
Push self

PREINIT:
int rc;

CODE:
self -> success = 1;

rc = git_push_finish(self -> push);
git_check_error(rc);

if (self -> callbacks.status != NULL) {
rc = git_push_status_foreach(
self -> push,
git_push_status_cbb,
&self -> callbacks);
git_check_error(rc);
self);

if (rc != GIT_EUSER)
git_check_error(rc);
}

RETVAL = newSViv(self -> success);

OUTPUT: RETVAL

SV *
unpack_ok(self)
Push self
Expand All @@ -84,6 +92,10 @@ update_tips(self)

CODE:
push = GIT_SV_TO_PTR(Push, self);

if (!push -> success)
croak_usage("Push did not complete successfully");

remote = GIT_SV_TO_MAGIC(self);
remote_ptr = INT2PTR(Remote, SvIV((SV *) remote));

Expand Down

0 comments on commit a1f0ff4

Please sign in to comment.