ExternalProject: Strip trailing space from git hash
ExternalProject: Better handling of git remote branches

ExternalProject handles git remote branches by commit hash. Due to
this, the git repository ends in detached states, and local commits
are discarded.

This patch uses "git pull --rebase" for remote branches instead of
git checkout. If there are local changes, "git stash" is used to save
the changes and restore them after the pull. If any of these operation
fails, it tries to restore the original status and exits with a fatal
error, asking the user to resolve the conflicts manually.

This also makes the behaviour of ExternalProject using git more similar
to the svn version, and probably more likely to what the user expects
by setting GIT_TAG to a branch.
Merge topic 'ExternalProject_GitUpdate' into next

64d78bd6 ExternalProject: Better handling of git remote branches
49bed21a ExternalProject: Strip trailing space from git hash