When two superconductors are electrically connected by a weak link--such as a tunnel barrier--a zero-resistance supercurrent can flow. This supercurrent is carried by Cooper pairs of electrons with a combined charge of twice the elementary charge, e. The 2e charge quantum is clearly visible in the height of voltage steps in Josephson junctions under microwave irradiation, and in the magnetic flux periodicity of h/2e (where h is Planck's constant) in superconducting quantum interference devices. Here we study supercurrents through a quantum dot created in a semiconductor nanowire by local electrostatic gating. Owing to strong Coulomb interaction, electrons only tunnel one-by-one through the discrete energy levels of the quantum dot. This nevertheless can yield a supercurrent when subsequent tunnel events are coherent. These quantum coherent tunnelling processes can result in either a positive or a negative supercurrent, that is, in a normal or a pi-junction, respectively. We demonstrate that the supercurrent reverses sign by adding a single electron spin to the quantum dot. When excited states of the quantum dot are involved in transport, the supercurrent sign also depends on the character of the orbital wavefunctions.