Skip to content

Commit c27fcbe

Browse files
author
Markus M. May
committed
Add deletion of repos, taken from pull request dergachev#19
1 parent 4e2b417 commit c27fcbe

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

app/models/repository/git_remote.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ class Repository::GitRemote < Repository::Git
1010
PATH_PREFIX = PLUGIN_ROOT + "/repos/"
1111

1212
before_validation :initialize_clone
13-
14-
# TODO: figure out how to do this safely (if at all)
15-
# before_deletion :rm_removed_repo
16-
# def rm_removed_repo
17-
# if Repository.find_all_by_url(repo.url).length <= 1
18-
# system "rm -Rf #{self.clone_path}"
19-
# end
20-
# end
13+
before_destroy :remove_unused_repos
2114

2215
def extra_clone_url
2316
return nil unless extra_info
@@ -85,6 +78,16 @@ def initialize_clone
8578
errors.add :extra_clone_url, err if err
8679
end
8780

81+
## Deletes repository directory if it's inside plugin directory (i.e. belongs to plugin)
82+
## and this repo is not used by other repositories
83+
def remove_unused_repos
84+
inside_plugin_bundle = self.clone_path.include? PATH_PREFIX
85+
nobody_else_need_it = Repository.where(url: self.relative_url).count <= 1
86+
if inside_plugin_bundle && nobody_else_need_it
87+
system "rm -Rf #{self.clone_path}"
88+
end
89+
end
90+
8891
# equality check ignoring trailing whitespace and slashes
8992
def two_remotes_equal(a,b)
9093
a.chomp.gsub(/\/$/,'') == b.chomp.gsub(/\/$/,'')

0 commit comments

Comments
 (0)