Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Git-Wrapper CPAN distribution.

Report information
The Basics
Id: 75955
Status: resolved
Priority: 0/
Queue: Git-Wrapper

People
Owner: GENEHACK [...] cpan.org
Requestors: felliott [...] virginia.edu
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: bug in short argument handling
Hello, The current Git::Wrapper is prepending '=' to argument values. While this is correct for long- form arguments like 'git commit --message', it is incorrect for short-form arguments like 'git commit -m'. In those cases the '=' will be assumed to be part of the value. This is troublesome for short-form args without a corresponding long-form arg, e.g. 'git checkout -b'. I've attached a patch (with tests) that checks the length of the argument and only prepends the '=' if it's greater than one. Thank you for your work on this module! Cheers, Fitz Elliott
Subject: 0001-fix-short-arg-vs-long-arg-handling-add-tests.patch
From 1cffdd25e9526829ae7eec659d498c0487d71034 Mon Sep 17 00:00:00 2001 From: Fitz Elliott <fitz.elliott@gmail.com> Date: Wed, 21 Mar 2012 16:56:56 -0400 Subject: [PATCH] fix short arg vs long arg handling; add tests Git::Wrapper was prepending '=' to argument values. While this is correct for long-form arguments like 'git commit --message', it is incorrect for short-form arguments like 'git commit -m'. In those cases the '=' will be assumed to be part of the value. This is troublesome for short-form args without a corresponding long-form arg, e.g. 'git checkout -b'. This patch checks the length of the argument and only prepends the '=' if it's greater than one. diff --git a/lib/Git/Wrapper.pm b/lib/Git/Wrapper.pm index e6c215a..6f6c07f 100644 --- a/lib/Git/Wrapper.pm +++ b/lib/Git/Wrapper.pm @@ -39,6 +39,14 @@ sub _opt { ; } +sub _val { + my $name = shift; + my $val = shift; + return $val eq '1' ? "" + : length($name) == 1 ? $val + : "=$val"; +} + sub _cmd { my $self = shift; @@ -54,7 +62,7 @@ sub _cmd { my $val = delete $opt->{$_}; next if $val eq '0'; - push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val"); + push @cmd, _opt($name) . _val($name, $val); } push @cmd, $cmd; @@ -66,7 +74,7 @@ sub _cmd { ( $name, $val ) = $self->_message_tempfile( $val ) if $self->_win32_multiline_commit_msg( $cmd, $name, $val ); - push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val"); + push @cmd, _opt($name) . _val($name, $val); } push @cmd, @_; diff --git a/t/basic.t b/t/basic.t index bc1a665..c1d9475 100644 --- a/t/basic.t +++ b/t/basic.t @@ -97,4 +97,28 @@ SKIP: { }; +# test --message vs. -m +my @arg_tests = ( + ['message', 'long_arg_no_spaces', 'long arg, no spaces in val', ], + ['message', 'long arg with spaces', 'long arg, spaces in val', ], + ['m', 'short_arg_no_spaces', 'short arg, no spaces in val', ], + ['m', 'short arg w spaces', 'short arg, spaces in val', ], +); +my $arg_file = IO::File->new(">" . File::Spec->catfile($dir, qw(argument_testfile))); +for my $arg_test (@arg_tests) { + my ($flag, $msg, $descr) = @$arg_test; + $arg_file->print("$msg\n"); + $git->add('argument_testfile'); + $git->commit({ $flag => $msg }); + my ($arg_log) = $git->log('-n 1'); + is $arg_log->message, "$msg\n", "argument test: $descr"; +} + + +$git->checkout({b => 'new_branch'}); +my ($new_branch) = grep {m/^\*/} $git->branch; +$new_branch =~ s/^\*\s+|\s+$//g; +is $new_branch, 'new_branch', 'new branch name is correct'; + + done_testing(); -- 1.7.9.4
On Wed Mar 21 17:15:26 2012, felliott wrote: Show quoted text
> Hello, > > The current Git::Wrapper is prepending '=' to argument values. > While this is correct for long- > form arguments like 'git commit --message', it is incorrect for short- > form arguments like 'git > commit -m'. In those cases the '=' will be assumed to be part of the > value. This is troublesome > for short-form args without a corresponding long-form arg, e.g. 'git > checkout -b'. I've attached > a patch (with tests) that checks the length of the argument and only > prepends the '=' if it's > greater than one. > > Thank you for your work on this module! >
And thank you for the patch! I applied it in git commit 70adbc1 and expect to release a new version later this afternoon. (Apologies for taking so long to get around to applying this.) Ticket is closed with thanks. j.