diff options
author | Teddy Wing | 2018-04-19 23:08:09 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-19 23:08:09 +0200 |
commit | 7bb9292f60c8889b2a3529748679025d73e9d645 (patch) | |
tree | 01422160246237352e966825acd6bed62c7a7942 | |
parent | 56de9223a7220f8b679c7e9c6c41d6acdb744a90 (diff) | |
download | git-branch-list-7bb9292f60c8889b2a3529748679025d73e9d645.tar.bz2 |
git-branch-list(drop): Support multiple branches with similar names
Previously if you had multiple branches with similar names, they could
all be deleted when deleting a single one.
For example:
$ git branch-list
1 a-branch-with-suffix
2 a-branch
$ git branch-list drop 2
$ git branch-list
$
Change the regex used to match branches to drop to match the whole line,
so we don't accidentally delete a branch when it has a positive partial
match.
-rwxr-xr-x | git-branch-list | 2 | ||||
-rw-r--r-- | t/103-drop-does-not-drop-other-branches-with-similar-names.t | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/git-branch-list b/git-branch-list index 0c6a74a..cde44f2 100755 --- a/git-branch-list +++ b/git-branch-list @@ -78,7 +78,7 @@ function drop_branch () { done for branch in "${branch_names[@]}"; do - sed -i '.bak' "/$branch/d" "$DATABASE" + sed -i '.bak' "/^$branch$/d" "$DATABASE" done rm "${DATABASE}.bak" diff --git a/t/103-drop-does-not-drop-other-branches-with-similar-names.t b/t/103-drop-does-not-drop-other-branches-with-similar-names.t new file mode 100644 index 0000000..05360cb --- /dev/null +++ b/t/103-drop-does-not-drop-other-branches-with-similar-names.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +use Bin qw($BIN); + +chdir 't-git-repo' or die $!; + +system('git checkout -b first-similar-name'); +ok !$?; + +system("$BIN save"); +ok !$?; + +system('git checkout -b first'); +ok !$?; + +system("$BIN save"); +ok !$?; + +system("$BIN drop"); +ok !$?; + +my $branch_list = qx($BIN); +is $branch_list, ' 1 first-similar-name +'; + + +# Teardown +system('git checkout master'); +system('git branch -d first first-similar-name'); +system("$BIN clear"); + + +done_testing; |