既出のGitCommand.exeを小改造してremote repositoryのurlを変更する用途に使う
現在のlatestあるいはworkingコピーを新しいサーバーにmigrateしても、それをいじり続けると、push先が古いサーバーにいってしまいますから、古い方から切り替える必要があります。新しいサーバからcloneしてもいいのですが、workingコピーが増えて混乱の元ですから、この処置が必要になります。
Remote Repository Manger 1.5に同梱されているGitCommand.exeのデフォルトコマンド文字列を変更します。ソースを開示するのは初めてだったかな?まず。
Edit1->Textの内容を“status”から”remote set-url origin “に変更します。従って、フォームは、

で、Unit1.hは、
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TLabel *Label1;
TMemo *Memo1;
TEdit *Edit1;
TLabel *Label2;
void __fastcall DoItClick(TObject *Sender);
void __fastcall Edit1KeyPress(TObject *Sender, System::WideChar &Key);
void __fastcall FormShow(TObject *Sender);
private: // ユーザー宣言
public: // ユーザー宣言
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endifUnit1.cppは、
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <System.IOUtils.hpp>
#include <Clipbrd.hpp>
#include <iostream>
#include <sstream>
#include <System.StrUtils.hpp>
#include "popen.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
AnsiString target;
if( ParamCount() > 0 ){
target = TPath::GetDirectoryName(ParamStr(1));
//ShowMessage(target);
}
else
target = GetCurrentDir();
//AnsiString currentDirectory = GetCurrentDir();
Label1->Caption = target;
ChDir(target);
Memo1->Lines->Clear();
}
void __fastcall TForm1::DoItClick(TObject *Sender)
{
//Memo1->Lines->Add(rtn.c_str());
DWORD retcode;
String rtn;
String command = "git";
//std::string newurl = AnsiString(Clipboard()->AsText).c_str();
//std::string args = "remote set-url origin " + newurl;
String args = Edit1->Text;
rtn = Popen(command,args,retcode);
Memo1->Lines->Clear();
Label2->Caption = IntToStr((int)retcode);
//std::stringstream ss{rtn.c_str()};
//std::string s;
// while ( getline(ss, s) ){
// Memo1->Lines->Add(s.c_str());
//}
TStringDynArray array = SplitString(rtn,"\n");
//Memo1->Lines->Text = array;
for (int i = 0; i < array.Length; ++i)
Memo1->Lines->Add(array[i].c_str()); // OK
//Memo1->Lines->Add(rtn);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, System::WideChar &Key)
{
if( Key == VK_RETURN ){
//Button1Click(Sender);
DoItClick(Sender);
Key = 0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
Edit1->SetFocus();
}
//---------------------------------------------------------------------------
他にはいつものpopen.hとpopen.cppが必要です。このサイトを探せば見つかります。全体のプロジェクトは、

のようになります。

実行するとこうなりますから、変更先のclone_urlをRRMのレポジトリリストからcopyしてきて、Edit1->Textの末尾にpasteします。それでリターン。実際のテストは、他のプラグイン同様にIDEに組み込んでテストします。旧GitCommand.exeをlaunchして、statusを消して、remote set-url origin new_clone_urlを入れても全く同じですが、備忘録みたいなものですかね。あとclone_urlが複雑な場合、copy and pasteで済む便利さがあります。
git remote set-url origin new_clone_url
が憶えられないんだよね。だから備忘録代わりなんです。


コメント