Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ronan Dunklau
committed
Mar 1, 2013
1 parent
e257f38
commit e1534ad
Showing
36 changed files
with
600 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/perl -w | ||
|
||
use strict; | ||
use warnings; | ||
use v5.10; | ||
use Test::More; | ||
use App::Sqitch; | ||
use Path::Class qw(dir file); | ||
use Locale::TextDomain qw(App-Sqitch); | ||
use Test::MockModule; | ||
use Test::Exception; | ||
use Test::File qw(file_not_exists_ok file_exists_ok); | ||
|
||
use File::Temp; | ||
use File::Copy::Recursive qw(dircopy); | ||
use lib 't/lib'; | ||
use Git::Wrapper; | ||
use MockOutput; | ||
|
||
my $CLASS = 'App::Sqitch::Command::checkout'; | ||
require_ok $CLASS or die; | ||
|
||
$ENV{SQITCH_CONFIG} = 'nonexistent.conf'; | ||
$ENV{SQITCH_USER_CONFIG} = 'nonexistent.user'; | ||
$ENV{SQITCH_SYSTEM_CONFIG} = 'nonexistent.sys'; | ||
|
||
isa_ok $CLASS, 'App::Sqitch::Command'; | ||
can_ok $CLASS, qw( | ||
options | ||
configure | ||
log_only | ||
execute | ||
deploy_variables | ||
revert_variables | ||
); | ||
|
||
|
||
my $tmp_git_dir = File::Temp->newdir(); | ||
|
||
ok my $sqitch = App::Sqitch->new( | ||
top_dir => Path::Class::dir($tmp_git_dir), | ||
_engine => 'sqlite', | ||
), 'Load a sqitch object'; | ||
|
||
my $config = $sqitch->config; | ||
|
||
# Test configure(). | ||
is_deeply $CLASS->configure($config, {}), { | ||
verify => 0, | ||
mode => 'all', | ||
log_only => 0, | ||
}, 'Check default configuration'; | ||
|
||
isa_ok my $checkout = App::Sqitch::Command->load({ | ||
sqitch => $sqitch, | ||
command => 'checkout', | ||
config => $config, | ||
}), $CLASS, 'checkout command'; | ||
|
||
|
||
# Copy the git repo to a temp directory | ||
my $git = $checkout->git; | ||
|
||
$git->clone(Path::Class::Dir->new('t', 'git', 'checkout'), $tmp_git_dir); | ||
|
||
|
||
file_exists_ok file ($tmp_git_dir, 'sqitch.plan'), | ||
'The plan file exists'; | ||
|
||
file_exists_ok file ($tmp_git_dir, '.git'), | ||
'The repository exists'; | ||
|
||
|
||
my $plan = $sqitch->plan; | ||
my $changes = $plan->changes; | ||
is $changes, 2, "The plan file from the git repository is ok"; | ||
is $git->dir, $tmp_git_dir, 'Git is in the tmp dir'; | ||
|
||
# Make sure the local branches are actually created. | ||
$git->checkout('another_branch'); | ||
$git->pull(); | ||
$git->checkout('yet_another_branch'); | ||
$git->pull(); | ||
$git->checkout('master'); | ||
$git->pull(); | ||
|
||
# Mock the engine | ||
my $mock_engine = Test::MockModule->new('App::Sqitch::Engine::sqlite'); | ||
my @dep_args; | ||
$mock_engine->mock(deploy => sub { shift; @dep_args = @_ }); | ||
my @rev_args; | ||
$mock_engine->mock(revert => sub { shift; @rev_args = @_ }); | ||
my @vars; | ||
$mock_engine->mock(set_variables => sub { shift; push @vars => [@_] }); | ||
|
||
# Deploy the thing. | ||
$sqitch->engine->deploy; | ||
|
||
$checkout->execute('another_branch'); | ||
|
||
is_deeply +MockOutput->get_info, [ | ||
[__x 'Last change before the branches diverged: {last_change}', | ||
last_change => 'users @alpha'], | ||
], 'Should not revert anything, and deploy to another_branch'; | ||
|
||
|
||
throws_ok {$checkout->execute('another_branch')} 'App::Sqitch::X', | ||
'Should throw an error when switching to the same branch'; | ||
|
||
is $@->ident, 'checkout', 'The error when switching to the same branch should be ident'; | ||
is $@->message, __x('Already on branch {branch}', | ||
branch=> 'another_branch'), 'The error message should match'; | ||
|
||
$checkout->execute('yet_another_branch'); | ||
is_deeply +MockOutput->get_info, [ | ||
[__x 'Last change before the branches diverged: {last_change}', | ||
last_change => 'users @alpha'], | ||
], 'Should not revert anything, and deploy to another_branch'; | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = true | ||
[remote "origin"] | ||
url = /home/ro/projets/sqitch/t/git/checkout_repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unnamed repository; edit this file 'description' to name the repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to check the commit log message taken by | ||
# applypatch from an e-mail message. | ||
# | ||
# The hook should exit with non-zero status after issuing an | ||
# appropriate message if it wants to stop the commit. The hook is | ||
# allowed to edit the commit message file. | ||
# | ||
# To enable this hook, rename this file to "applypatch-msg". | ||
|
||
. git-sh-setup | ||
test -x "$GIT_DIR/hooks/commit-msg" && | ||
exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} | ||
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to check the commit log message. | ||
# Called by "git commit" with one argument, the name of the file | ||
# that has the commit message. The hook should exit with non-zero | ||
# status after issuing an appropriate message if it wants to stop the | ||
# commit. The hook is allowed to edit the commit message file. | ||
# | ||
# To enable this hook, rename this file to "commit-msg". | ||
|
||
# Uncomment the below to add a Signed-off-by line to the message. | ||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg | ||
# hook is more suited to it. | ||
# | ||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') | ||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" | ||
|
||
# This example catches duplicate Signed-off-by lines. | ||
|
||
test "" = "$(grep '^Signed-off-by: ' "$1" | | ||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { | ||
echo >&2 Duplicate Signed-off-by lines. | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to prepare a packed repository for use over | ||
# dumb transports. | ||
# | ||
# To enable this hook, rename this file to "post-update". | ||
|
||
exec git update-server-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to verify what is about to be committed | ||
# by applypatch from an e-mail message. | ||
# | ||
# The hook should exit with non-zero status after issuing an | ||
# appropriate message if it wants to stop the commit. | ||
# | ||
# To enable this hook, rename this file to "pre-applypatch". | ||
|
||
. git-sh-setup | ||
test -x "$GIT_DIR/hooks/pre-commit" && | ||
exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} | ||
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to verify what is about to be committed. | ||
# Called by "git commit" with no arguments. The hook should | ||
# exit with non-zero status after issuing an appropriate message if | ||
# it wants to stop the commit. | ||
# | ||
# To enable this hook, rename this file to "pre-commit". | ||
|
||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
# If you want to allow non-ascii filenames set this variable to true. | ||
allownonascii=$(git config hooks.allownonascii) | ||
|
||
# Redirect output to stderr. | ||
exec 1>&2 | ||
|
||
# Cross platform projects tend to avoid non-ascii filenames; prevent | ||
# them from being added to the repository. We exploit the fact that the | ||
# printable range starts at the space character and ends with tilde. | ||
if [ "$allownonascii" != "true" ] && | ||
# Note that the use of brackets around a tr range is ok here, (it's | ||
# even required, for portability to Solaris 10's /usr/bin/tr), since | ||
# the square bracket bytes happen to fall in the designated range. | ||
test $(git diff --cached --name-only --diff-filter=A -z $against | | ||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 | ||
then | ||
echo "Error: Attempt to add a non-ascii file name." | ||
echo | ||
echo "This can cause problems if you want to work" | ||
echo "with people on other platforms." | ||
echo | ||
echo "To be portable it is advisable to rename the file ..." | ||
echo | ||
echo "If you know what you are doing you can disable this" | ||
echo "check using:" | ||
echo | ||
echo " git config hooks.allownonascii true" | ||
echo | ||
exit 1 | ||
fi | ||
|
||
# If there are whitespace errors, print the offending file names and fail. | ||
exec git diff-index --check --cached $against -- |
Oops, something went wrong.