Skip to content

Commit 3f7df8f

Browse files
mistollnuclearsandwich
authored andcommitted
Do not overwrite template files, if they exist (#516)
This patch enables to place files in the debian folder of the upstream repository. Currently it's possible to place additional files into that folder. However if the file is present in the bloom template set (like rules.em) that file is overwritten. See #507.
1 parent f222c28 commit 3f7df8f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

bloom/generators/debian/generator.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ def __place_template_folder(group, src, dst, gbp=False):
147147
if not os.path.exists(dst):
148148
os.makedirs(dst)
149149
if os.path.exists(template_dst):
150-
debug("Removing existing file '{0}'".format(template_dst))
151-
os.remove(template_dst)
152-
with io.open(template_dst, 'w', encoding='utf-8') as f:
153-
if not isinstance(template, str):
154-
template = template.decode('utf-8')
155-
# Python 2 API needs a `unicode` not a utf-8 string.
156-
elif sys.version_info.major == 2:
157-
template = template.decode('utf-8')
158-
f.write(template)
159-
shutil.copystat(template_abs_path, template_dst)
150+
debug("Not overwriting existing file '{0}'".format(template_dst))
151+
else:
152+
with io.open(template_dst, 'w', encoding='utf-8') as f:
153+
if not isinstance(template, str):
154+
template = template.decode('utf-8')
155+
# Python 2 API needs a `unicode` not a utf-8 string.
156+
elif sys.version_info.major == 2:
157+
template = template.decode('utf-8')
158+
f.write(template)
159+
shutil.copystat(template_abs_path, template_dst)
160160

161161

162162
def place_template_files(path, build_type, gbp=False):
@@ -838,7 +838,9 @@ def place_template_files(self, build_type, debian_dir='debian'):
838838
place_template_files('.', build_type, gbp=True)
839839
# Commit results
840840
execute_command('git add ' + debian_dir)
841-
execute_command('git commit -m "Placing debian template files"')
841+
_, has_files, _ = execute_command('git diff --cached --name-only', return_io=True)
842+
if has_files:
843+
execute_command('git commit -m "Placing debian template files"')
842844

843845
def get_releaser_history(self):
844846
# Assumes that this is called in the target branch

0 commit comments

Comments
 (0)