-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgit_rm_all_log.py
executable file
·91 lines (81 loc) · 3.02 KB
/
git_rm_all_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python
# -*- encoding: utf-8 -*-
###########################################################################
# Module Writen to OpenERP, Open Source Management Solution
#
# Copyright (c) 2013 Vauxoo - http://www.vauxoo.com/
# All Rights Reserved.
# info Vauxoo ([email protected])
############################################################################
# Coded by: moylop260 ([email protected])
############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import argparse
import os
from tempfile import gettempdir
from git_run import GitRun
class GitRmAllLog(object):
def __init__(self, git_url,
root_path=None):
self.git_url = git_url
if root_path is None:
root_path = gettempdir()
else:
root_path = os.path.expandvars(
os.path.expanduser(root_path)
)
self.git_run_obj = GitRun(git_url, None)
self.git_run_obj.path = os.path.join(
root_path,
self.git_run_obj.owner,
self.git_run_obj.repo
)
def rm_all_log(self, items):
self.git_run_obj.update()
refs = self.git_run_obj.get_ref_data(['refs/heads']).keys()
for ref in refs:
self.git_run_obj.checkout_bare(ref)
self.git_run_obj.run([
"filter-branch", "-f", "--tree-filter",
"rm -rf %s" % items, "HEAD"
])
def main():
parser = argparse.ArgumentParser(
"Remove all git log of a file or folder from"
" a git repo url")
parser.add_argument(
"git_repo_url",
help="Specify url repository git to work.",
)
parser.add_argument(
"items_to_delete",
help="Specify files or folders to delete (split with spaces).",
)
parser.add_argument(
'--root-path', dest='root_path',
help="Root path to save scripts generated."
"\nDefault: 'tmp' dir of your O.S.",
default=None,
)
args = parser.parse_args()
git_repo_url = args.git_repo_url
items_to_delete = args.items_to_delete
root_path = args.root_path
git_rm_all_log_obj = GitRmAllLog(git_repo_url, root_path)
git_rm_all_log_obj.rm_all_log(items_to_delete)
if __name__ == '__main__':
main()