diff options
-rwxr-xr-x | git-branch-list | 5 | ||||
-rw-r--r-- | t/104-drop-works-with-branch-names-with-slashes.t | 29 |
2 files changed, 31 insertions, 3 deletions
diff --git a/git-branch-list b/git-branch-list index 75167a3..cce35e3 100755 --- a/git-branch-list +++ b/git-branch-list @@ -78,10 +78,9 @@ function drop_branch () { done for branch in "${branch_names[@]}"; do - sed -i '.bak' "/^$branch$/d" "$DATABASE" + fgrep --line-regexp --invert-match "$branch" "$DATABASE" > "$DATABASE.bak" + mv "${DATABASE}.bak" "$DATABASE" done - - rm "${DATABASE}.bak" } function clear_branches () { diff --git a/t/104-drop-works-with-branch-names-with-slashes.t b/t/104-drop-works-with-branch-names-with-slashes.t new file mode 100644 index 0000000..8219e3e --- /dev/null +++ b/t/104-drop-works-with-branch-names-with-slashes.t @@ -0,0 +1,29 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +use Bin qw($BIN); + +chdir 't-git-repo' or die $!; + +system('git checkout -b feature/with-slashes'); +ok !$?; + +system("$BIN save"); +ok !$?; + +system("$BIN drop"); +ok !$?; + +my $branch_list = qx($BIN); +is $branch_list, ''; + + +# Teardown +system('git checkout master'); +system('git branch -d feature/with-slashes'); + + +done_testing; |