The requirements.txt handling during upm add did no checking to see whether the file had a newline or not before adding one. This would lead to situations where attempting to upm add dep2 to a file that already contained dep1 would result in dep1dep2.
What changed
Determine whether the file already has a newline. If it does, maintain that newline as we add new lines to the file. If it doesn't, maintain its absence.
Test plan
echo -n pytest > requirements.txt
upm add flask
Prior to this change, you'd end up with pytestFlask\n. After this change, we will end up with pytest\nFlask
We hardcode \n everywhere today, supporting Windows will require significant effort, this change doesn't preclude that in the future, so I'm gonna proceed.
Why
The
requirements.txt
handling duringupm add
did no checking to see whether the file had a newline or not before adding one. This would lead to situations where attempting toupm add dep2
to a file that already containeddep1
would result indep1dep2
.What changed
Determine whether the file already has a newline. If it does, maintain that newline as we add new lines to the file. If it doesn't, maintain its absence.
Test plan
Prior to this change, you'd end up with
pytestFlask\n
. After this change, we will end up withpytest\nFlask