Skip to content

Commit

Permalink
RF+ENH: rerun: Process inputs before unlocking/removing any files
Browse files Browse the repository at this point in the history
When content isn't present for a file that was added/modified in a
revision, it'd be better to remove the file rather than trying to
unlock it, which fails.  But if we do that, we should make sure we
process inputs first since that step may retrieve an added/modified
file (perhaps via --input=.).  To do both these things, piggyback on
run's outputs argument.
  • Loading branch information
kyleam committed May 10, 2018
1 parent 1ce28ac commit 21a8b95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions datalad/interface/rerun.py
Expand Up @@ -14,6 +14,7 @@
import logging
from itertools import dropwhile
import json
import os
import re
import sys

Expand Down Expand Up @@ -316,14 +317,15 @@ def __call__(
# bring back the entire state of the tree with #1424, but
# we limit ourself to file addition/not-in-place-modification
# for now
for r in ds.unlock(new_or_modified(ds, hexsha),
return_type='generator', result_xfm=None):
yield r
auto_outputs = (os.path.relpath(ap["path"], ds.path)
for ap in new_or_modified(ds, hexsha))
outputs = run_info.get("outputs", [])
auto_outputs = [p for p in auto_outputs if p not in outputs]

for r in run_command(run_info['cmd'],
dataset=ds,
inputs=run_info.get("inputs", []),
outputs=run_info.get("outputs", []),
outputs=outputs + auto_outputs,
message=message or rev["run_message"],
rerun_info=run_info):
yield r
Expand Down
4 changes: 3 additions & 1 deletion datalad/interface/run.py
Expand Up @@ -283,7 +283,9 @@ def run_command(cmd, dataset=None, inputs=None, outputs=None,
'exit': cmd_exitcode if cmd_exitcode is not None else 0,
'chain': rerun_info["chain"] if rerun_info else [],
'inputs': inputs,
'outputs': outputs
# Get outputs from the rerun_info because rerun adds new/modified files
# to the outputs argument.
'outputs': rerun_info["outputs"] if rerun_info else outputs
}
if rel_pwd is not None:
# only when inside the dataset to not leak information
Expand Down
4 changes: 4 additions & 0 deletions datalad/interface/tests/test_run.py
Expand Up @@ -157,6 +157,10 @@ def test_rerun(path, nodspath):
# Or --since= to run all reachable commits.
ds.rerun(since="")
eq_('xxxxxxxxxx\n', open(probe_path).read())
# If a file is dropped, we remove it instead of unlocking it.
ds.drop(probe_path, check=False)
ds.rerun()
eq_('x\n', open(probe_path).read())
# If the history to rerun has a merge commit, we abort.
ds.repo.checkout("HEAD~3", options=["-b", "topic"])
with open(opj(path, "topic-file"), "w") as f:
Expand Down

0 comments on commit 21a8b95

Please sign in to comment.