Skip to content

Commit 820c7b7

Browse files
Add worktrees.prune
Signed-off-by: Ofir Petrushka <hatkyinc@gmail.com>
1 parent eee23c3 commit 820c7b7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/git/lib.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ def worktree_remove(dir)
337337
command('worktree', ['remove', dir])
338338
end
339339

340+
def worktree_prune
341+
command('worktree', ['prune'])
342+
end
343+
340344
def list_files(ref_dir)
341345
dir = File.join(@git_dir, 'refs', ref_dir)
342346
files = []

lib/git/worktrees.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ def to_s
3939
end
4040
out
4141
end
42+
43+
def prune
44+
@base.lib.worktree_prune
45+
end
4246
end
4347
end

tests/units/test_worktree.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env ruby
2-
2+
require 'fileutils'
33
require File.dirname(__FILE__) + '/../test_helper'
44

55
SAMPLE_LAST_COMMIT = '5e53019b3238362144c2766f02a2c00d91fcc023'
@@ -47,4 +47,16 @@ def test_worktree_add_and_remove
4747

4848
assert_equal(@git.worktrees.size, 2)
4949
end
50+
51+
def test_worktree_prune
52+
assert_equal(2, @git.worktrees.size)
53+
54+
@git.worktree('/tmp/pp1').add
55+
assert_equal(3, @git.worktrees.size)
56+
@git.worktrees.prune
57+
assert_equal(2, @git.worktrees.size)
58+
FileUtils.rm_rf('/tmp/pp1')
59+
@git.worktrees.prune
60+
assert_equal(1, @git.worktrees.size)
61+
end
5062
end

0 commit comments

Comments
 (0)