It has been suggested that second-order nonlinearities could be used for quantum logic at the single-photon level. Specifically, successive two-photon processes in principle could accomplish the phase shift (conditioned on the presence of two photons in the low frequency modes) $ |011 rangle longrightarrow i|100 rangle longrightarrow -|011 rangle $. We have analyzed a recent scheme proposed by Xia et al. to induce such a conditional phase shift between two single-photon pulses propagating at different speeds through a nonlinear medium with a nonlocal response. We present here an analytical solution for the most general case, i.e. for an arbitrary response function, initial state, and pulse velocity, which supports their numerical observation that a $pi$ phase shift with unit fidelity is possible, in principle, in an appropriate limit. We also discuss why this is possible in this system, despite the theoretical objections to the possibility of conditional phase shifts on single photons that were raised some time ago by Shapiro and by one of us.