aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-04-19 23:44:13 +0200
committerTeddy Wing2018-04-19 23:44:13 +0200
commit3f6e62684b1fb1167435c6fa4f6c6f02aaff3937 (patch)
treef928f9fbf3cb33032477e468f3510f2f5506a170
parentd1617e2f29d1a8080602b60cd83ffddb01e88875 (diff)
downloadgit-branch-list-3f6e62684b1fb1167435c6fa4f6c6f02aaff3937.tar.bz2
git-branch-list(drop): Fix deletion for branches with slashes
Previously, if a branch name had slashes in it, the `drop` command would fail. This is because it used `sed` with `/` separators, and the unescaped slashes in the branch name would mess up sed's pattern. Change this to use grep instead of sed so we don't have to worry about escaping and special characters in branch names.
-rwxr-xr-xgit-branch-list5
-rw-r--r--t/104-drop-works-with-branch-names-with-slashes.t29
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;