aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-04-19 23:36:11 +0200
committerTeddy Wing2018-04-19 23:36:11 +0200
commitd1617e2f29d1a8080602b60cd83ffddb01e88875 (patch)
treecc805e1ae97049a3f8eab1c04938121df84e3c10
parent56de9223a7220f8b679c7e9c6c41d6acdb744a90 (diff)
parent92b7edb0d84ac0109f28da57fccf4a9d87896b1e (diff)
downloadgit-branch-list-d1617e2f29d1a8080602b60cd83ffddb01e88875.tar.bz2
Merge branch 'fix-drop-for-branches-with-similar-names'
-rwxr-xr-xgit-branch-list4
-rw-r--r--t/103-drop-does-not-drop-other-branches-with-similar-names.t37
2 files changed, 39 insertions, 2 deletions
diff --git a/git-branch-list b/git-branch-list
index 0c6a74a..75167a3 100755
--- a/git-branch-list
+++ b/git-branch-list
@@ -44,7 +44,7 @@ __EOF__
function save_branch () {
local branch=$(branch_or_current_branch "$1")
- if fgrep "$branch" "$DATABASE" > /dev/null; then
+ if fgrep --line-regexp "$branch" "$DATABASE" > /dev/null; then
return 1
fi
@@ -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;