Solution (source code)

= Solution

Choose
$$
0<\delta<\min\{d_g(p,q),r_p\},
$$
where $r_p$ is a normal radius at $p$. Take piecewise smooth curves $c_j$ from $p$ to $q$ such that $L_g(c_j)\to d_g(p,q)$. Each $c_j$ first leaves the normal ball $B_g(p,\delta)$ at a point $p_j$. The <Gauss lemma> gives $d_g(p,p_j)=\delta$. The geodesic sphere
$$
S_g(p,\delta)=\exp_p\{v\in T_pM:|v|_g=\delta\}
$$
is <compact space>[compact], because the tangent-space sphere is compact and $\exp_p$ is defined on it. After taking a <convergent subsequence>, let $p_j\to p_0$.

The part of $c_j$ after $p_j$ has length at least $d_g(p_j,q)$, so continuity of the <Riemannian distance> gives
$$
\delta+d_g(p_0,q)
\leq\lim_{j\to\infty}L_g(c_j)
=d_g(p,q).
$$
The <triangle inequality> gives the reverse inequality. Therefore
$$
d_g(p,p_0)=\delta,
\qquad
d_g(p,p_0)+d_g(p_0,q)=d_g(p,q).
$$