For $x\leq 0$, $g(x)=\int_0^x 0dt =0$.
For $0\leq x \leq 1$ , $g(x)=\int_0^x tdt=x^2/2$.
For $1\leq x\leq2$, $g(x)=\int_0^1 tdt +\int_1^x (2-t)dt=2x -x^2/2 -1$.
For $x\geq 2$, $g(x)=\int_0^1 tdt +\int_1^2 (2-t)dt + \int_2^x 0dt=1$.
The idea is to break the integral up as a sum of integrals on intervals where each piece of the piecewise-defined integrand lives, using the fact that $\int_a^c=\int_a^b +\int_b^c$.
And since the upper limit is variable, how you break it up will depend on what the upper limit is; I've considered all the possibilities above. Putting them all together,
$$ g(x)= \begin{cases} 0 & x\leq 0 \\\ x^2/2 & 0\leq x\leq 1 \\\ 2x-x^2/2 - 1& 1\leq x\leq 2 \\\ 1 & x \geq 2 \end{cases} $$