@@ -285,6 +285,28 @@ def test_ensure_alt_path(runner, paths, style):
285285 assert run .out == ''
286286 assert paths .work .join (filename ).read ().strip () == 'test-data'
287287
288+ @pytest .mark .usefixtures ("ds1_repo_copy" )
289+ @pytest .mark .parametrize ("readonly" , [None , "true" , "false" ])
290+ def test_template_readonly (runner , yadm_cmd , paths , tst_sys , readonly ):
291+ """Remove write permission for template result file.
292+
293+ If the `yadm.template-read-only` configuration is not set to false,
294+ the resulting file from processing a template should has no write permission.
295+ """
296+ # set the value of template read-only
297+ if readonly :
298+ runner (yadm_cmd ("config" , "yadm.template-read-only" , readonly ))
299+
300+ utils .create_alt_files (paths , f"##template.default" )
301+ run = runner (yadm_cmd ("alt" ))
302+
303+ for stale_path in [utils .ALT_FILE1 , utils .ALT_FILE2 ]:
304+ write_perm_mask = os .stat (paths .work .join (stale_path )).st_mode & 0o222
305+ if readonly == "false" :
306+ assert write_perm_mask > 0
307+ else :
308+ assert write_perm_mask == 0
309+
288310
289311def setup_standard_yadm_dir (paths ):
290312 """Configure a yadm home within the work tree"""
0 commit comments