Fix regression introduced in last commit

When target was not in the repositories a NoneType + str error is poped.
To checking for it is done before set_global()