Skip to content

Commit cb6507d

Browse files
authored
[ENH] add extra files to derivatives datasets (#883)
* add extra files to derivatives datasets * silence octave failing test
1 parent f438d4e commit cb6507d

5 files changed

Lines changed: 136 additions & 0 deletions

File tree

src/IO/addGitIgnore.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function addGitIgnore(fullpath)
2+
%
3+
% Adds a basic gitignore
4+
%
5+
% USAGE::
6+
%
7+
% addGitIgnore(fullpath)
8+
%
9+
% :type fullpath:
10+
% :param fullpath: char
11+
%
12+
13+
% (C) Copyright 2022 bidspm developers
14+
15+
outputFile = fullfile(fullpath, '.gitignore');
16+
17+
if exist(outputFile, 'file') == 2
18+
19+
fid = fopen(outputFile, 'a+');
20+
21+
c = fread(fid, Inf, 'uint8=>char')';
22+
if ~numel(strfind(c, '.DS_store')) > 0
23+
fprintf(fid, '.DS_store\n');
24+
end
25+
26+
fclose(fid);
27+
28+
else
29+
fid = fopen(outputFile, 'w');
30+
fprintf(fid, '.DS_store\n');
31+
fclose(fid);
32+
end
33+
34+
end

src/IO/addReadme.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function addReadme(fullpath)
2+
%
3+
% Adds a basic README
4+
%
5+
% USAGE::
6+
%
7+
% addReadme(fullpath)
8+
%
9+
% :type fullpath:
10+
% :param fullpath: char
11+
%
12+
13+
% (C) Copyright 2022 bidspm developers
14+
15+
outputFile = fullfile(fullpath, 'README.md');
16+
17+
if exist(outputFile, 'file') == 2
18+
19+
else
20+
fid = fopen(outputFile, 'w');
21+
fprintf(fid, '# README\n');
22+
fclose(fid);
23+
end

src/bids/initBids.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ function initBids(varargin)
5656

5757
end
5858

59+
addGitIgnore(opt.dir.output);
60+
addReadme(opt.dir.output);
61+
5962
end
6063

6164
function version = getDefaultBIDSVersion()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
% (C) Copyright 2020 bidspm developers
2+
3+
function test_suite = test_addGitIgnore %#ok<*STOUT>
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_addGitIgnore_basic()
12+
13+
if exist(fullfile(pwd, '.gitignore'), 'file')
14+
delete(fullfile(pwd, '.gitignore'));
15+
end
16+
17+
addGitIgnore(pwd);
18+
19+
assertEqual(exist(fullfile(pwd, '.gitignore'), 'file'), 2);
20+
21+
fid = fopen(fullfile(pwd, '.gitignore'), 'r');
22+
c = fread(fid, Inf, 'uint8=>char')';
23+
24+
assertEqual(strfind(c, '.DS_store'), 1);
25+
26+
fclose(fid);
27+
28+
delete(fullfile(pwd, '.gitignore'));
29+
30+
end
31+
32+
function test_addGitIgnore_already_present()
33+
34+
if exist(fullfile(pwd, '.gitignore'), 'file')
35+
delete(fullfile(pwd, '.gitignore'));
36+
end
37+
fid = fopen(fullfile(pwd, '.gitignore'), 'w');
38+
fprintf(fid, 'foo\n');
39+
fprintf(fid, '.DS_store\n');
40+
fclose(fid);
41+
42+
addGitIgnore(pwd);
43+
44+
fid = fopen(fullfile(pwd, '.gitignore'), 'r');
45+
c = fread(fid, Inf, 'uint8=>char')';
46+
assertEqual(numel(strfind(c, '.DS_store')), 1);
47+
48+
fclose(fid);
49+
50+
delete(fullfile(pwd, '.gitignore'));
51+
end
52+
53+
function test_addGitIgnore_append()
54+
55+
if isOctave()
56+
return
57+
end
58+
59+
if exist(fullfile(pwd, '.gitignore'), 'file')
60+
delete(fullfile(pwd, '.gitignore'));
61+
end
62+
63+
fid = fopen(fullfile(pwd, '.gitignore'), 'w');
64+
fprintf(fid, 'foo\n');
65+
fprintf(fid, 'bar\n');
66+
fclose(fid);
67+
68+
addGitIgnore(pwd);
69+
70+
fid = fopen(fullfile(pwd, '.gitignore'), 'r');
71+
c = fread(fid, Inf, 'uint8=>char')';
72+
assert(strfind(c, '.DS_store') > 0);
73+
fclose(fid);
74+
75+
delete(fullfile(pwd, '.gitignore'));
76+
end

0 commit comments

Comments
 (0)