Example #1
0
void Gitarre::onPushAction ()
{
	Repository *repo = Repos[RepoView->currentIndex().row()];
	 // TODO: Add remote selection

	git_remote *remote = repo->GetRemote(0);
	struct git_remote_callbacks cb = { 1,
										Gitarre::sRProgressCb,
										Gitarre::sRCompletionCb,
										Gitarre::sRCredentialsCb,
										Gitarre::sRTransferProgressCb,
										Gitarre::sRUpdateTipsCb,
										(void *)this
	};
	git_remote_set_callbacks (remote, &cb);

	// fix git protocol address
	const char *url = git_remote_url (remote);
	if (!strncmp (url, "git@", 4))
	{
		int len = strlen (url) - 4;
		char *_url = (char *) malloc (len + 9);
		strcpy (_url, "https://");
		strncpy (_url + 8, url + 4, len);
		_url [len + 8] = 0;
		char *sc = strrchr (_url, ':');
		if (sc)
			*sc = '/';
		git_remote_set_url (remote, _url);
	}

	StatusLabel->show();
	StatusLabel->setText ("Connecting to remote...");
	StatusProgress->show();
	StatusProgress->setRange (0,0);
	git_remote_connect (remote, GIT_DIRECTION_PUSH);
	if (git_remote_connected (remote))
	{
		git_push *push;
		git_push_new (&push, remote);
		git_push_add_refspec (push, "refs/heads/master:refs/heads/master");

		git_push_set_callbacks (push,
								Gitarre::sPPackbuilderProgressCb,
								(void *)this,
								Gitarre::sPTransferProgressCb,
								(void *)this);
		git_push_finish (push);
		if (git_push_unpack_ok (push))
		{
			git_push_status_foreach (push, Gitarre::sPStatusForeachCb, (void *)this);
			git_push_update_tips (push);
		}
		git_push_free (push);
		git_remote_disconnect (remote);
		git_remote_free (remote);
	}
	else
	{
		const git_error *error = giterr_last ();
		if (error->message)
			QMessageBox::warning(this, "Connect to remote", QString ("Failed to connect to ") + git_remote_url (remote) + " :\n" + error->message);
		else
			QMessageBox::warning(this, "Connect to remote", QString ("Failed to connect to ") + git_remote_url (remote));
	}
	StatusLabel->hide();
	StatusProgress->hide();
}
Example #2
0
int _go_git_push_set_callbacks(git_push *push, void *packbuilder_progress_data, void *transfer_progress_data)
{
	return git_push_set_callbacks(push, packbuilderProgress, packbuilder_progress_data, pushTransferProgress, transfer_progress_data);
}