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

fcm commit: don't commit message file #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/FCM/System/CM/CommitMessage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ our $SUBVERSION_CONFIG_FILE = catfile((getpwuid($<))[7], qw{.subversion/config})

__PACKAGE__->class({gui => '$', util => '&'},
{action_of => {
'ctx' => sub {$CTX->new()},
'edit' => \&_edit,
'load' => \&_load,
'notify' => \&_notify,
'path' => \&_path,
'save' => \&_save,
'temp' => \&_temp,
'ctx' => sub {$CTX->new()},
'edit' => \&_edit,
'load' => \&_load,
'notify' => \&_notify,
'path' => \&_path,
'path_base' => sub {$COMMIT_MESSAGE_BASE},
'save' => \&_save,
'temp' => \&_temp,
}},
);

Expand Down Expand Up @@ -289,6 +290,10 @@ Raise a CM_COMMIT_MESSAGE event with the $commit_message_ctx.
Return the path to the commit message file in $dir or the current working
directory if $dir is not specified.

=item $commit_message_util->path($dir)

Return the base name of the commit message file.

=item $commit_message_util->save($commit_message_ctx, $path)

Save the commit message to $path (or the standard location if $path is not
Expand Down
11 changes: 11 additions & 0 deletions lib/FCM1/Cm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ our %CLI_MESSAGE_FOR_ERROR = (
NOT_EXIST => "%s: does not exist.\n",
PARENT_NOT_EXIST => "%s: parent %s no longer exists.\n",
RMTREE => "%s: cannot remove.\n",
ST_CI_MESG_FILE => "Attempt to add commit message file:\n%s",
ST_CONFLICT => "File(s) in conflicts:\n%s",
ST_MISSING => "File(s) missing:\n%s",
ST_OOD => "File(s) out of date:\n%s",
Expand Down Expand Up @@ -473,6 +474,16 @@ sub cm_commit {
return _cm_abort(FCM1::Cm::Abort->NULL);
}

# Abort if attempt to add commit message file
my $ci_mesg_file_base = $COMMIT_MESSAGE_UTIL->path_base();
my @bad_status = grep {$_ =~ qr{^A.*?\s$ci_mesg_file_base\n}m} @status;
if (@bad_status) {
for my $bad_status (@bad_status) {
$CLI_MESSAGE->('ST_CI_MESG_FILE', $bad_status);
}
return _cm_abort(FCM1::Cm::Abort->FAIL);
}

# Get associated URL of current working copy
my $layout = $SVN->get_layout($SVN->get_info()->[0]->{url});

Expand Down
58 changes: 58 additions & 0 deletions t/fcm-commit/03-message-file.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# ------------------------------------------------------------------------------
# (C) British Crown Copyright 2006-14 Met Office.
#
# This file is part of FCM, tools for managing and building source code.
#
# FCM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FCM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FCM. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------
# Tests for "fcm commit", attempt to add commit message file.
#-------------------------------------------------------------------------------
. $(dirname $0)/test_header
#-------------------------------------------------------------------------------
tests 6
#-------------------------------------------------------------------------------
svnadmin create foo
svn co -q file://$PWD/foo 'test-work'
touch 'test-work/#commit_message#'
svn add 'test-work/#commit_message#'
export SVN_EDITOR='cat'
#-------------------------------------------------------------------------------
# Tests fcm commit, bad commit file 1
TEST_KEY="$TEST_KEY_BASE-1"
run_fail "$TEST_KEY" fcm commit --svn-non-interactive 'test-work'
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <<__OUT__
$PWD/test-work: working directory changed to top of working copy.
__OUT__
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__ERR__'
[ERROR] Attempt to add commit message file:
A #commit_message#
[FAIL] FCM1::Cm::Abort: abort

__ERR__
#-------------------------------------------------------------------------------
# Tests fcm commit, bad commit file 2
TEST_KEY="$TEST_KEY_BASE-2"
cd 'test-work'
run_fail "$TEST_KEY" fcm commit --svn-non-interactive
cd ..
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__ERR__'
[ERROR] Attempt to add commit message file:
A #commit_message#
[FAIL] FCM1::Cm::Abort: abort

__ERR__
#-------------------------------------------------------------------------------
exit