-
Notifications
You must be signed in to change notification settings - Fork 166
/
downGitList.py
91 lines (56 loc) · 1.82 KB
/
downGitList.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
# Requires: https://github.com/gitpython-developers/GitPython
"""This script converts a github repo into a list for
directory and file bruteforcing but has to clone the whole repo to do it"""
__author__ = "Scot Berner"
import git
import sys, getopt, shutil
# Store repo URL and output file names
repoURL=''
ofile=''
# Read command line args
myopts, args = getopt.getopt(sys.argv[1:], "u:o:")
###############################
# o == option
# a == argument passed to the o
###############################
for o, a in myopts:
if o == '-u':
repoURL=a
elif o == '-o':
ofile=a
else:
print("Usage: %s -u <repo url> -o <out file>" % sys.argv[0])
print("IE: %s -u https://github.com/WordPress/WordPress -o wordpress.txt" % sys.argv[0])
# Display input and output file name passed as the args
print ("[*] Repo URL : %s " % (repoURL) )
print ("[*] Outfile : %s " % (ofile) )
if ofile == "":
print "[*] Outfile required"
sys.exit()
#infer repo name from URL
repoURLArr = repoURL.split("/")
tempArr = repoURLArr[4].split(".")
repoName = tempArr[0]
#create repo dumping path
chkPath = "/tmp/" + repoName
#create git object
grepo = git.Git()
#clone repo
gitCMD = grepo.execute(["git", "clone", repoURL, chkPath])
#create git object in repo that we created
grepo = git.Git(chkPath)
#get list of files under source control for the master branch
repoFiles = grepo.execute(["git", "ls-tree", "-r", "master", "--full-name"])
#convert list of files to array of each line
repoFiles = repoFiles.split("\n")
#open file for writing with clobber
outFile = open(ofile, 'w+')
#write each file name to txt file
for line in repoFiles:
#print line.split('\t')[1]
outFile.write(line.split('\t')[1] + "\n")
outFile.close
print "[*] Cleaning up..."
#delect repo files
shutil.rmtree(chkPath)