16
16
DEVELOP = "develop-"
17
17
DEVELOP_DEFAULT = "all develop branches"
18
18
19
- DIFF_FORMAT = """
20
19
21
- You can download a zip of this exercise [here](https://github.com/udacity/ud843-QuakeReport/archive/{number}-Exercise-{name}.zip), \
22
- and a zip of the solution [here](https://github.com/udacity/ud843-QuakeReport/archive/{number}-Solution-{name}.zip). \
23
- Also, you can find a visual summary of the solution [here](https://github.com/udacity/ud843-QuakeReport/compare/\
24
- {number}-Exercise-{name}...{number}-Solution-{name}).
25
-
26
- """
27
20
28
21
29
22
def flatten (repo_dir , target_dir , student , develop_branches , remove_branches , links ):
@@ -32,33 +25,16 @@ def flatten(repo_dir, target_dir, student, develop_branches, remove_branches, li
32
25
if develop_branches == DEVELOP_DEFAULT :
33
26
develop_branches = [branch for branch in repo .branches if DEVELOP in branch .name ]
34
27
35
- if remove_branches :
36
- remove_local_branches (repo , student , develop_branches )
37
-
38
- flat = len (develop_branches ) == 1
39
-
40
- # print develop_branches
28
+ remove_local_branches (repo , student , develop_branches )
41
29
42
30
try :
43
31
temp_dir = tempfile .mkdtemp ()
44
- try :
45
- # current_branch = repo.active_branch
46
- # print "Stashing"
47
- # repo.git.stash()
48
-
49
- for develop in develop_branches :
50
- to_temp_dir (repo , repo_dir , develop , temp_dir , flat , links )
51
- if links :
52
- insert_diff_links (temp_dir )
53
-
54
- copy_snapshots (repo , student , temp_dir , target_dir )
55
- finally :
56
- pass
57
- # if current_branch:
58
- # repo.git.checkout(current_branch)
59
- # print "Popping"
60
- # if repo.git.stash("list"):
61
- # repo.git.stash("pop")
32
+
33
+
34
+ for develop in develop_branches :
35
+ to_temp_dir (repo , repo_dir , develop , temp_dir )
36
+
37
+ copy_snapshots (repo , student , temp_dir , target_dir )
62
38
finally :
63
39
if os .path .exists (temp_dir ):
64
40
shutil .rmtree (temp_dir )
@@ -74,7 +50,7 @@ def remove_local_branches(repo, student, develop_branches):
74
50
repo .git .branch (branch .name , "-D" )
75
51
76
52
77
- def to_temp_dir (repo , repo_dir , develop , temp_dir , flat , links ):
53
+ def to_temp_dir (repo , repo_dir , develop , temp_dir ):
78
54
for rev in repo .git .rev_list (develop ).split ("\n " ):
79
55
commit = repo .commit (rev )
80
56
branch_name = clean_commit_message (commit .message )
@@ -87,21 +63,12 @@ def to_temp_dir(repo, repo_dir, develop, temp_dir, flat, links):
87
63
repo .git .checkout (commit )
88
64
print "Saving snapshot of:" , branch_name
89
65
repo .git .clean ("-fdx" )
90
- if flat :
91
- target_dir = os .path .join (temp_dir , branch_name )
92
- else :
93
- folder_name = develop .name .split ("-" ,1 )[1 ]
94
- target_dir = os .path .join (temp_dir , folder_name , branch_name )
66
+ folder_name = develop .name .split ("-" ,1 )[1 ]
67
+ target_dir = os .path .join (temp_dir , folder_name , branch_name )
95
68
96
69
shutil .copytree (repo_dir , target_dir ,
97
70
ignore = shutil .ignore_patterns (* IGNORE_PATTERNS ))
98
71
99
- if links :
100
- with open (os .path .join (target_dir , "README.md" ), "a" ) as readme :
101
- print branch_name
102
- number , _ , name = branch_name .split ("-" )
103
- readme .write (DIFF_FORMAT .format (number = number , name = name ))
104
-
105
72
106
73
def clean_commit_message (message ):
107
74
first_line = message .split ("\n " )[0 ]
@@ -110,13 +77,6 @@ def clean_commit_message(message):
110
77
return safe_message [:MAX_LENGTH ] if len (safe_message ) > MAX_LENGTH else safe_message
111
78
112
79
113
- def insert_diff_links (temp_dir ):
114
- for item in os .listdir (temp_dir ):
115
- number , _ , name = item .split ("-" )
116
- with open (os .path .join (temp_dir , item , "README.md" ), "a" ) as readme :
117
- readme .write (DIFF_FORMAT .format (number = number , name = name ))
118
-
119
-
120
80
def copy_snapshots (repo , student , temp_dir , target_dir ):
121
81
if target_dir == os .getcwd ():
122
82
repo .git .checkout (student )
0 commit comments