-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgit_steps.py
More file actions
187 lines (143 loc) · 5.04 KB
/
git_steps.py
File metadata and controls
187 lines (143 loc) · 5.04 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"""Steps for features tests."""
# pylint: disable=function-redefined, missing-function-docstring, import-error, not-callable
# pyright: reportRedeclaration=false, reportAttributeAccessIssue=false, reportCallIssue=false
import os
import pathlib
import subprocess
from behave import given # pylint: disable=no-name-in-module
from dfetch.util.util import in_directory
from features.steps.generic_steps import call_command, extend_file, generate_file
from features.steps.manifest_steps import generate_manifest
def create_repo():
subprocess.call(
["git", "init", "--initial-branch=master", "--quiet"]
) # Be quiet about using master as the default branch
subprocess.call(["git", "config", "user.email", "you@example.com"])
subprocess.call(["git", "config", "user.name", "John Doe"])
if os.name == "nt":
# Creates zombie fsmonitor-daemon process that holds files
# (see https://github.com/git-for-windows/git/issues/3326)
subprocess.call(
["git", "config", "--global", "core.usebuiltinfsmonitor", "false"]
)
def commit_all(msg):
subprocess.call(["git", "add", "-A"])
subprocess.call(["git", "commit", "-m", f'"{msg}"'])
def tag(name: str):
subprocess.call(["git", "tag", "-a", name, "-m", "'Some tag'"])
@given("a git repo with the following submodules")
def step_impl(context):
create_repo()
for submodule in context.table:
subprocess.call(
["git", "submodule", "add", submodule["url"], submodule["path"]]
)
with in_directory(submodule["path"]):
subprocess.call(["git", "checkout", submodule["revision"]])
commit_all("Added submodules")
@given('a new tag "{tagname}" is added to git-repository "{name}"')
def step_impl(context, tagname, name):
remote_path = os.path.join(context.remotes_dir, name)
with in_directory(remote_path):
extend_file("README.md", f"New line for creating {tagname}")
commit_all("Extend readme")
tag(tagname)
@given('a git-repository "{name}" with the manifest:')
@given('a git repository "{name}"')
def step_impl(context, name):
remote_path = os.path.join(context.remotes_dir, name)
pathlib.Path(remote_path).mkdir(parents=True, exist_ok=True)
with in_directory(remote_path):
create_repo()
generate_file("README.md", f"Generated file for {name}")
if context.text:
generate_manifest(context)
commit_all("Initial commit")
tag("v1")
@given('a git-repository "{name}" with the files')
def step_impl(context, name):
remote_path = os.path.join(context.remotes_dir, name)
pathlib.Path(remote_path).mkdir(parents=True, exist_ok=True)
with in_directory(remote_path):
create_repo()
for file in context.table:
generate_file(file["path"], "some content")
commit_all("Initial commit")
tag("v1")
@given('MyProject with dependency "SomeProject.git" that must be updated')
def step_impl(context):
manifest = """
manifest:
version: 0.0
projects:
- name: SomeProject
url: some-remote-server/SomeProject.git
tag: v1
"""
generate_manifest(
context,
"dfetch.yaml",
contents=manifest,
path="MyProject",
)
context.execute_steps(
"""
Given a git repository "SomeProject.git"
And all projects are updated in MyProject
And a new tag "v2" is added to git-repository "SomeProject.git"
"""
)
generate_manifest(
context,
"dfetch.yaml",
contents=manifest.replace("v1", "v2"),
path="MyProject",
)
@given("a fetched and committed MyProject with the manifest")
def step_impl(context):
pathlib.Path("MyProject").mkdir(parents=True, exist_ok=True)
with in_directory("MyProject"):
create_repo()
generate_manifest(context)
call_command(context, ["update"])
commit_all("Initial commit")
@given('"{path}" in {directory} is changed with')
def step_impl(context, directory, path):
with in_directory(directory):
extend_file(path, context.text)
@given('"{path}" in {directory} is changed and committed with')
def step_impl(context, directory, path):
with in_directory(directory):
extend_file(path, context.text)
commit_all("A change")
@given("MyProject with applied patch 'diff.patch'")
def step_impl(context):
manifest = """
manifest:
version: '0.0'
remotes:
- name: github-com-dfetch-org
url-base: https://github.com/dfetch-org/test-repo
projects:
- name: ext/test-repo-tag
tag: v2.0
dst: ext/test-repo-tag
patch: diff.patch
"""
generate_manifest(
context,
"dfetch.yaml",
contents=manifest,
)
patch_file = """
diff --git a/README.md b/README.md
index 32d9fad..62248b7 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# Test-repo
-A test repo for testing dfetch.
+A test repo for testing patch.
"""
generate_file(os.path.join(os.getcwd(), "diff.patch"), patch_file)
call_command(context, ["update"])