-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user credentials when opening remote projects
- Loading branch information
D. Alfano (Nexus6)
committed
Oct 31, 2023
1 parent
39b2623
commit 9986a73
Showing
6 changed files
with
202 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
* Copyright 2023 Nexus6 <[email protected]> | ||
* All rights reserved. Distributed under the terms of the MIT license. | ||
* Based on TrackGit (https://github.com/HaikuArchives/TrackGit) | ||
* Original author: Hrishikesh Hiraskar <[email protected]> | ||
* Original author: Hrishikesh Hiraskar <[email protected]> | ||
* Copyright Hrishikesh Hiraskar and other HaikuArchives contributors (see GitHub repo for details) | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <SupportDefs.h> | ||
|
@@ -33,6 +33,8 @@ using namespace std::filesystem; | |
|
||
namespace Genio::Git { | ||
|
||
const int CANCEL_CREDENTIALS = -123; | ||
|
||
class GitException { | ||
public: | ||
GitException(int error, BString const& message) | ||
|
@@ -45,37 +47,38 @@ namespace Genio::Git { | |
|
||
int Error() noexcept { return _error; } | ||
BString Message() noexcept { return _message; } | ||
|
||
private: | ||
int _error; | ||
BString _message; | ||
}; | ||
|
||
class GitRepository { | ||
class GitRepository { | ||
public: | ||
GitRepository(const path& path); | ||
~GitRepository(); | ||
|
||
const BPath& Clone(const string& url, const BPath& localPath, | ||
git_indexer_progress_cb callback); | ||
|
||
|
||
const BPath& Clone(const string& url, const BPath& localPath, | ||
git_indexer_progress_cb callback, | ||
git_credential_acquire_cb authentication_callback); | ||
|
||
bool InitCheck() { return fInitCheck; }; | ||
void Init(const path& repo, const path& localPath); | ||
|
||
vector<string> GetBranches(); | ||
int SwitchBranch(string branch); | ||
|
||
vector<pair<string, string>> GetFiles(); | ||
|
||
string PullChanges(bool rebase); | ||
|
||
private: | ||
git_repository *fRepository; | ||
path fRepositoryPath; | ||
bool fInitCheck; | ||
|
||
string _ExecuteCommand(const string& command) const; | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Hrishikesh Hiraskar <[email protected]> | ||
* Copyright 2023 Nexus6 <[email protected]> | ||
* All rights reserved. Distributed under the terms of the MIT license. | ||
*/ | ||
#include "GitCredentialsWindow.h" | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <AppKit.h> | ||
#include <Catalog.h> | ||
#include <LayoutBuilder.h> | ||
#include <SupportKit.h> | ||
|
||
#undef B_TRANSLATION_CONTEXT | ||
#define B_TRANSLATION_CONTEXT "GitCredentialsWindow" | ||
|
||
GitCredentialsWindow::GitCredentialsWindow(char* usernamePtr, char* passwordPtr) | ||
: | ||
BWindow(BRect(0, 0, 300, 150), B_TRANSLATE("Git - User Credentials"), | ||
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | ||
| B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_CLOSABLE) | ||
{ | ||
fUsernamePtr = usernamePtr; | ||
fPasswordPtr = passwordPtr; | ||
|
||
fUsername = new BTextControl(B_TRANSLATE("Username:"), "", NULL); | ||
fPassword = new BTextControl(B_TRANSLATE("Password:"), "", NULL); | ||
fPassword->TextView()->HideTyping(true); | ||
BButton* fOK = new BButton("ok", B_TRANSLATE("OK"), | ||
new BMessage(kCredOK)); | ||
BButton* fCancel = new BButton("cancel", B_TRANSLATE("Cancel"), | ||
new BMessage(kCredCancel)); | ||
|
||
BLayoutBuilder::Group<>(this, B_VERTICAL) | ||
.SetInsets(B_USE_WINDOW_INSETS) | ||
.AddGrid() | ||
.AddTextControl(fUsername, 0, 0) | ||
.AddTextControl(fPassword, 0, 1) | ||
.End() | ||
.AddGroup(B_HORIZONTAL) | ||
.AddGlue() | ||
.Add(fCancel) | ||
.Add(fOK) | ||
.End(); | ||
|
||
CenterOnScreen(); | ||
Show(); | ||
} | ||
|
||
|
||
void | ||
GitCredentialsWindow::MessageReceived(BMessage* msg) | ||
{ | ||
switch (msg->what) { | ||
case kCredOK: | ||
strcpy(fUsernamePtr, fUsername->Text()); | ||
strcpy(fPasswordPtr, fPassword->Text()); | ||
Quit(); | ||
break; | ||
case kCredCancel: | ||
strcpy(fUsernamePtr, ""); | ||
strcpy(fPasswordPtr, ""); | ||
Quit(); | ||
break; | ||
// default: | ||
// BWindow::MessageReceived(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2018, Hrishikesh Hiraskar <[email protected]> | ||
* All rights reserved. Distributed under the terms of the MIT license. | ||
*/ | ||
|
||
#ifndef _CREDENTIALS_WINDOW_H_ | ||
#define _CREDENTIALS_WINDOW_H_ | ||
|
||
#include <posix/sys/time.h> | ||
|
||
#include <InterfaceKit.h> | ||
|
||
enum { | ||
kCredOK, | ||
kCredCancel | ||
}; | ||
|
||
/** | ||
* The Credentials Window class. | ||
*/ | ||
class GitCredentialsWindow : public BWindow { | ||
/** | ||
* The text control for username. | ||
*/ | ||
BTextControl* fUsername; | ||
/** | ||
* The text control for password. | ||
*/ | ||
BTextControl* fPassword; | ||
/** | ||
* The username pointer. | ||
*/ | ||
char* fUsernamePtr; | ||
/** | ||
* The password pointer. | ||
*/ | ||
char* fPasswordPtr; | ||
public: | ||
GitCredentialsWindow(char*, char*); | ||
virtual void MessageReceived(BMessage*); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters