private final ObjectId getRemoteHead(final Git gitSession)
			throws InvalidRemoteException, TransportException, GitAPIException,
			IOException, InterruptedException {
		if (!this.USE_SSH.getValue()) {
			final String refS = "refs/heads/" + this.BRANCH.value();
			final FetchCommand fetch = gitSession
					.fetch()
					.setRefSpecs(
							new RefSpec(refS + ":refs/remotes/origin/"
									+ this.BRANCH.value()))
					.setProgressMonitor(getProgressMonitor());


			final Ref ref = fetch.call().getAdvertisedRef(refS);
			if (ref == null) {
				return null;
			}
			return ref.getObjectId();
		}
		final File f = this.repoRoot.resolve(".git", "FETCH_HEAD").toFile();
		final InputStream in;
		final byte[] buffer = new byte[40];
		final ObjectId id;
		if (executeNativeGit("git", "fetch", "origin") != 0) {
			return null;
		}
		in = this.io.openIn(f);
		in.read(buffer);
		this.io.close(in);
		id = ObjectId.fromString(new String(buffer));
		return id;
	}