This repository was archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-all-python.py
More file actions
92 lines (75 loc) · 2.86 KB
/
Copy pathgit-all-python.py
File metadata and controls
92 lines (75 loc) · 2.86 KB
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
92
from os import mkdir
from os.path import exists
from shutil import rmtree
from progress.bar import Bar
from progress.spinner import MoonSpinner
from libs.cmdLineParser import cmdLineParser
from libs.git import Git
class GitAllPython:
def __init__(self) -> None:
args = cmdLineParser()
self.repoURL: str = args.url[0]
self.src: str = args.src[0]
self.start: int = args.start
self.stride: int = args.stride
def checkSourcePathAvailibility(self) -> bool:
return exists(self.src)
def checkDestinationPathAvailibility(self) -> bool:
return exists("output")
def makeDesitinationPath(self, dst: str) -> bool:
try:
mkdir(dst)
except FileExistsError:
return False
return True
def deleteRepo(self) -> bool:
return rmtree(self.src)
if __name__ == "__main__":
gap = GitAllPython()
git = Git()
with MoonSpinner(message="Starting program... ") as spinner:
# Check to see if git is installed
if not git.checkIfGitInstalled():
print("git is not installed. Exiting program...")
exit(1)
else:
spinner.next()
# Check to see if the Source folder already exists
if gap.checkSourcePathAvailibility():
print("{} already exists. Exiting program...".format(gap.src))
exit(2)
else:
spinner.next()
# Check to see if the Output folder already exists
if type(gap.checkDestinationPathAvailibility()) is str:
print("Output folder has already been created. Exiting program...")
exit(3)
else:
spinner.next()
# Create the Output folder
if not gap.makeDesitinationPath(dst="output"):
print("Unable to create output folder. Exiting program...")
exit(4)
else:
spinner.next()
# Clone the git repository
print("Cloning git repository {} to local machine... ".format(gap.repoURL))
git.gitClone(repoURL=gap.repoURL, dst=gap.src)
# Check to make sure that the cloned repo is a git repository
if not git.checkIfGitRepository(src=gap.src):
print(
"{} is not a valid git repository. Exiting program...".format(gap.repoURL)
)
exit(5)
# Get the commit hash codes
chc = git.gitCommitHashCodes(sourceFolder=gap.src)
# Iterate through the hash codes
with Bar(message="Exploding commits from {}".format(gap.src), max=len(chc)) as bar:
for commit in chc:
# Create a folder for that specific hash code
gap.makeDesitinationPath(dst="output/" + commit)
# Create git repo that tracks the changes for a specific commit
git.gitRepoCreate(src=gap.src, dst="output/" + commit, chc=commit)
bar.next()
# Delete git repository
gap.deleteRepo()