Skip to content

Commit ddf03b3

Browse files
committed
BF: for datalad 0.10.0 - check/populate .gitattributes correctly
now that .gitattributes has some pre-populated by datalad settings we cannot just check for its existence, we need to check if any particular line is already defined
1 parent dddbd5f commit ddf03b3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

heudiconv/external/dlad.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,30 @@ def add_to_datalad(topdir, studydir, msg, bids):
6363
assert ds.is_installed()
6464
superds = ds
6565

66-
create_file_if_missing(
67-
op.join(studydir, '.gitattributes'),
68-
"""\
66+
# TODO: we need a helper (in DataLad ideally) to ease adding such
67+
# specifications
68+
gitattributes_path = op.join(studydir, '.gitattributes')
69+
# We will just make sure that all our desired rules are present in it
70+
desired_attrs = """\
6971
* annex.largefiles=(largerthan=100kb)
7072
*.json annex.largefiles=nothing
7173
*.txt annex.largefiles=nothing
7274
*.tsv annex.largefiles=nothing
7375
*.nii.gz annex.largefiles=anything
7476
*.tgz annex.largefiles=anything
7577
*_scans.tsv annex.largefiles=anything
76-
""")
78+
"""
79+
if op.exists(gitattributes_path):
80+
with open(gitattributes_path, 'rb') as f:
81+
known_attrs = [line.decode('utf-8').rstrip() for line in f.readlines()]
82+
else:
83+
known_attrs = []
84+
for attr in desired_attrs.split('\n'):
85+
if attr not in known_attrs:
86+
known_attrs.append(attr)
87+
with open(gitattributes_path, 'wb') as f:
88+
f.write('\n'.join(known_attrs).encode('utf-8'))
89+
7790
# so for mortals it just looks like a regular directory!
7891
if not ds.config.get('annex.thin'):
7992
ds.config.add('annex.thin', 'true', where='local')

0 commit comments

Comments
 (0)