Skip to content

Commit 4766004

Browse files
committed
Reproduce #350 Hash directory also hashes untracked files
1 parent 60090e0 commit 4766004

8 files changed

Lines changed: 155 additions & 58 deletions

features/check-git-repo.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ Feature: Checking dependencies from a git repository
137137
SomeProject : up-to-date (master - 90be799b58b10971691715bdc751fbe5237848a0)
138138
"""
139139

140+
Scenario: Change to ignored files are not reported
141+
Given a git repository "SomeProject.git"
142+
And a fetched and committed MyProject with the manifest
143+
"""
144+
manifest:
145+
version: 0.0
146+
projects:
147+
- name: SomeProject
148+
url: some-remote-server/SomeProject.git
149+
"""
150+
And files as '*.tmp' are ignored in git in MyProject
151+
And "SomeProject/IGNORE_ME.tmp" in MyProject is created
152+
When I run "dfetch check SomeProject"
153+
Then the output shows
154+
"""
155+
Dfetch (0.10.0)
156+
SomeProject : up-to-date (master - 90be799b58b10971691715bdc751fbe5237848a0)
157+
"""
158+
140159
Scenario: A non-existent remote is reported
141160
Given the manifest 'dfetch.yaml'
142161
"""

features/check-svn-repo.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,23 @@ Feature: Checking dependencies from a svn repository
158158
Dfetch (0.10.0)
159159
cutter-svn-tag : wanted (non-existent-tag), but not available at the upstream.
160160
"""
161+
162+
Scenario: Change to ignored files are not reported
163+
Given a svn-server "SomeProject" with the tag "v1"
164+
And a fetched and committed MySvnProject with the manifest
165+
"""
166+
manifest:
167+
version: 0.0
168+
projects:
169+
- name: SomeProject
170+
url: some-remote-server/SomeProject
171+
tag: 'v1'
172+
"""
173+
And files as '*.tmp' are ignored in 'MySvnProject/SomeProject' in svn
174+
And "SomeProject/IGNORE_ME.tmp" in MySvnProject is created
175+
When I run "dfetch check SomeProject"
176+
Then the output shows
177+
"""
178+
Dfetch (0.10.0)
179+
SomeProject : up-to-date (v1)
180+
"""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Feature: Guard against overwriting in git
2+
3+
Accidentally overwriting local changes could lead to introducing regressions.
4+
To make developers aware of overwriting, store hash after an update and compare
5+
this with hashes just before an update.
6+
7+
Background:
8+
Given a git repository "SomeProject.git"
9+
And a fetched and committed MyProject with the manifest
10+
"""
11+
manifest:
12+
version: 0.0
13+
projects:
14+
- name: SomeProject
15+
url: some-remote-server/SomeProject.git
16+
tag: v1
17+
"""
18+
And a new tag "v2" is added to git-repository "SomeProject.git"
19+
And "tag: v1" is replaced with "tag: v2" in "MyProject/dfetch.yaml"
20+
21+
Scenario: No update is done when hash is different
22+
Given "SomeProject/README.md" in MyProject is changed locally
23+
When I run "dfetch update"
24+
Then the output shows
25+
"""
26+
Dfetch (0.10.0)
27+
SomeProject : skipped - local changes after last update (use --force to overwrite)
28+
"""
29+
30+
Scenario: Force flag overrides local changes check
31+
Given "SomeProject/README.md" in MyProject is changed locally
32+
When I run "dfetch update --force"
33+
Then the output shows
34+
"""
35+
Dfetch (0.10.0)
36+
SomeProject : Fetched v2
37+
"""
38+
39+
Scenario: Ignored files are overwritten
40+
Given files as '*.tmp' are ignored in git in MyProject
41+
And "SomeProject/IGNORE_ME.tmp" in MyProject is created
42+
When I run "dfetch update SomeProject"
43+
Then the output shows
44+
"""
45+
Dfetch (0.10.0)
46+
SomeProject : Fetched v2
47+
"""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Feature: Guard against overwriting in svn
2+
3+
Accidentally overwriting local changes could lead to introducing regressions.
4+
To make developers aware of overwriting, store hash after an update and compare
5+
this with hashes just before an update.
6+
7+
Background:
8+
Given a svn-server "SomeProject" with the tag "v1"
9+
And a fetched and committed MySvnProject with the manifest
10+
"""
11+
manifest:
12+
version: 0.0
13+
projects:
14+
- name: SomeProject
15+
url: some-remote-server/SomeProject
16+
tag: 'v1'
17+
"""
18+
And a new tag "v2" is added to "SomeProject"
19+
And "tag: 'v1'" is replaced with "tag: 'v2'" in "MySvnProject/dfetch.yaml"
20+
21+
Scenario: No update is done when hash is different
22+
Given "SomeProject/README.md" in MySvnProject is changed locally
23+
When I run "dfetch update"
24+
Then the output shows
25+
"""
26+
Dfetch (0.10.0)
27+
SomeProject : skipped - local changes after last update (use --force to overwrite)
28+
"""
29+
30+
Scenario: Force flag overrides local changes check
31+
Given "SomeProject/README.md" in MySvnProject is changed locally
32+
When I run "dfetch update --force"
33+
Then the output shows
34+
"""
35+
Dfetch (0.10.0)
36+
SomeProject : Fetched v2
37+
"""
38+
39+
Scenario: Ignored files are overwritten
40+
Given files as '*.tmp' are ignored in 'MySvnProject/SomeProject' in svn
41+
And "SomeProject/IGNORE_ME.tmp" in MySvnProject is created
42+
When I run "dfetch update SomeProject"
43+
Then the output shows
44+
"""
45+
Dfetch (0.10.0)
46+
SomeProject : Fetched v2
47+
"""

features/guard-against-overwriting.feature

Lines changed: 0 additions & 25 deletions
This file was deleted.

features/steps/generic_steps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ def extend_file(path, content):
121121
print(line, file=existing_file)
122122

123123

124+
def replace_in_file(path: str, old: str, new: str) -> None:
125+
with open(path, "r", encoding="utf-8") as f:
126+
content = f.read()
127+
128+
content = content.replace(old, new)
129+
130+
with open(path, "w", encoding="utf-8") as f:
131+
f.write(content)
132+
133+
124134
def list_dir(path):
125135
# Get list of all nodes
126136
nodes = [os.path.normpath(path).split(os.sep)]
@@ -144,6 +154,11 @@ def list_dir(path):
144154
return result
145155

146156

157+
@given('"{old}" is replaced with "{new}" in "{path}"')
158+
def step_impl(_, old: str, new: str, path: str):
159+
replace_in_file(path, old, new)
160+
161+
147162
@given("the patch file '{name}'")
148163
def step_impl(context, name):
149164
generate_file(os.path.join(os.getcwd(), name), context.text)
@@ -187,6 +202,7 @@ def step_impl(context, args, path=None):
187202
call_command(context, args.split(), path)
188203

189204

205+
@given('"{path}" in {directory} is changed locally')
190206
@when('"{path}" in {directory} is changed locally')
191207
def step_impl(_, directory, path):
192208
with in_directory(directory):

features/steps/git_steps.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,6 @@ def step_impl(context, name):
9595
tag("v1")
9696

9797

98-
@given('MyProject with dependency "SomeProject.git" that must be updated')
99-
def step_impl(context):
100-
101-
manifest = """
102-
manifest:
103-
version: 0.0
104-
projects:
105-
- name: SomeProject
106-
url: some-remote-server/SomeProject.git
107-
tag: v1
108-
"""
109-
110-
generate_manifest(
111-
context,
112-
"dfetch.yaml",
113-
contents=manifest,
114-
path="MyProject",
115-
)
116-
context.execute_steps(
117-
"""
118-
Given a git repository "SomeProject.git"
119-
And all projects are updated in MyProject
120-
And a new tag "v2" is added to git-repository "SomeProject.git"
121-
"""
122-
)
123-
generate_manifest(
124-
context,
125-
"dfetch.yaml",
126-
contents=manifest.replace("v1", "v2"),
127-
path="MyProject",
128-
)
129-
130-
13198
@given("a fetched and committed MyProject with the manifest")
13299
def step_impl(context):
133100
pathlib.Path("MyProject").mkdir(parents=True, exist_ok=True)

features/steps/svn_steps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def step_impl(context, name, tag_name=None):
9090
create_tag(tag_name)
9191

9292

93+
@given('a new tag "{tag_name}" is added to "{name}"')
94+
def step_impl(_, tag_name, name):
95+
with in_directory(name):
96+
create_tag(tag_name)
97+
98+
9399
@given('a non-standard svn-server "{name}" with the files')
94100
def step_impl(context, name):
95101
repo_path = create_svn_server_and_repo(context, name)

0 commit comments

Comments
 (0)