Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 8e340b8

Browse files
Merge branch 'master' into feature/mac-support
2 parents 2a8f9ca + ccfeef3 commit 8e340b8

File tree

6 files changed

+308
-248
lines changed

6 files changed

+308
-248
lines changed

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,32 @@ public void RunCommandLineWindow(NPath workingDirectory)
7171
if (environment.IsWindows)
7272
{
7373
startInfo.FileName = "cmd";
74+
gitEnvironment.Configure(startInfo, workingDirectory);
7475
}
7576
else if (environment.IsMac)
7677
{
7778
// we need to create a temp bash script to set up the environment properly, because
7879
// osx terminal app doesn't inherit the PATH env var and there's no way to pass it in
7980

8081
var envVarFile = NPath.GetTempFilename();
81-
environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" });
82-
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8382
startInfo.FileName = "open";
8483
startInfo.Arguments = $"-a Terminal {envVarFile}";
84+
gitEnvironment.Configure(startInfo, workingDirectory);
85+
86+
var envVars = startInfo.EnvironmentVariables;
87+
var scriptContents = new[] {
88+
$"cd {envVars["GHU_WORKINGDIR"]}",
89+
$"PATH={envVars["GHU_FULLPATH"]}:$PATH /bin/bash"
90+
};
91+
environment.FileSystem.WriteAllLines(envVarFile, scriptContents);
92+
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8593
}
8694
else
8795
{
8896
startInfo.FileName = "sh";
97+
gitEnvironment.Configure(startInfo, workingDirectory);
8998
}
9099

91-
gitEnvironment.Configure(startInfo, workingDirectory);
92100
Process.Start(startInfo);
93101
}
94102

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AuthenticationView : Subview
2222
[SerializeField] private string two2fa = "";
2323

2424
[NonSerialized] private bool need2fa;
25-
[NonSerialized] private bool busy;
25+
[NonSerialized] private bool isBusy;
2626
[NonSerialized] private string errorMessage;
2727
[NonSerialized] private bool enterPressed;
2828
[NonSerialized] private string password = "";
@@ -58,7 +58,7 @@ private AuthenticationService AuthenticationService
5858
public override void InitializeView(IView parent)
5959
{
6060
base.InitializeView(parent);
61-
need2fa = busy = false;
61+
need2fa = isBusy = false;
6262
}
6363

6464
public override void OnEnable()
@@ -131,81 +131,83 @@ private void HandleEnterPressed()
131131

132132
private void OnGUILogin()
133133
{
134-
GUILayout.Space(3);
135-
GUILayout.BeginHorizontal();
134+
EditorGUI.BeginDisabledGroup(isBusy);
136135
{
137-
if (busy) GUI.enabled = false;
138-
username = EditorGUILayout.TextField(usernameLabel ,username, Styles.TextFieldStyle);
139-
GUI.enabled = true;
140-
}
141-
GUILayout.EndHorizontal();
142-
GUILayout.Space(Styles.BaseSpacing);
143-
GUILayout.BeginHorizontal();
144-
{
145-
if (busy) GUI.enabled = false;
146-
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
147-
GUI.enabled = true;
148-
}
149-
GUILayout.EndHorizontal();
136+
GUILayout.Space(3);
137+
GUILayout.BeginHorizontal();
138+
{
139+
username = EditorGUILayout.TextField(usernameLabel, username, Styles.TextFieldStyle);
140+
}
141+
GUILayout.EndHorizontal();
150142

151-
ShowErrorMessage();
143+
GUILayout.Space(Styles.BaseSpacing);
144+
GUILayout.BeginHorizontal();
145+
{
146+
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
147+
}
148+
GUILayout.EndHorizontal();
152149

153-
GUILayout.Space(Styles.BaseSpacing + 3);
150+
ShowErrorMessage();
154151

155-
if (busy) GUI.enabled = false;
156-
GUILayout.BeginHorizontal();
157-
GUILayout.FlexibleSpace();
158-
if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed))
159-
{
160-
GUI.FocusControl(null);
161-
busy = true;
162-
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
152+
GUILayout.Space(Styles.BaseSpacing + 3);
153+
GUILayout.BeginHorizontal();
154+
{
155+
GUILayout.FlexibleSpace();
156+
if (GUILayout.Button(loginButton) || (!isBusy && enterPressed))
157+
{
158+
GUI.FocusControl(null);
159+
isBusy = true;
160+
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
161+
}
162+
}
163+
GUILayout.EndHorizontal();
163164
}
164-
GUILayout.EndHorizontal();
165-
GUI.enabled = true;
165+
EditorGUI.EndDisabledGroup();
166166
}
167167

168168
private void OnGUI2FA()
169169
{
170170
GUILayout.BeginVertical();
171-
GUILayout.Label(twofaTitle, EditorStyles.boldLabel);
172-
GUILayout.Label(twofaDescription, EditorStyles.wordWrappedLabel);
173-
174-
GUILayout.Space(Styles.BaseSpacing);
175-
176-
GUILayout.BeginHorizontal();
177171
{
178-
if (busy) GUI.enabled = false;
179-
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
180-
GUI.enabled = true;
181-
}
182-
GUILayout.EndHorizontal();
183-
GUILayout.Space(Styles.BaseSpacing);
172+
GUILayout.Label(twofaTitle, EditorStyles.boldLabel);
173+
GUILayout.Label(twofaDescription, EditorStyles.wordWrappedLabel);
184174

185-
ShowErrorMessage();
175+
EditorGUI.BeginDisabledGroup(isBusy);
176+
{
177+
GUILayout.Space(Styles.BaseSpacing);
178+
GUILayout.BeginHorizontal();
179+
{
180+
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
181+
}
182+
GUILayout.EndHorizontal();
186183

187-
GUILayout.Space(Styles.BaseSpacing);
184+
GUILayout.Space(Styles.BaseSpacing);
185+
ShowErrorMessage();
188186

189-
if (busy) GUI.enabled = false;
190-
GUILayout.BeginHorizontal();
191-
GUILayout.FlexibleSpace();
192-
if (GUILayout.Button(backButton))
193-
{
194-
GUI.FocusControl(null);
195-
need2fa = false;
196-
Redraw();
197-
}
187+
GUILayout.Space(Styles.BaseSpacing);
188+
GUILayout.BeginHorizontal();
189+
{
190+
GUILayout.FlexibleSpace();
191+
if (GUILayout.Button(backButton))
192+
{
193+
GUI.FocusControl(null);
194+
need2fa = false;
195+
Redraw();
196+
}
197+
198+
if (GUILayout.Button(twofaButton) || (!isBusy && enterPressed))
199+
{
200+
GUI.FocusControl(null);
201+
isBusy = true;
202+
AuthenticationService.LoginWith2fa(two2fa);
203+
}
204+
}
205+
GUILayout.EndHorizontal();
198206

199-
if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed))
200-
{
201-
GUI.FocusControl(null);
202-
busy = true;
203-
AuthenticationService.LoginWith2fa(two2fa);
207+
GUILayout.Space(Styles.BaseSpacing);
208+
}
209+
EditorGUI.EndDisabledGroup();
204210
}
205-
GUILayout.EndHorizontal();
206-
207-
GUI.enabled = true;
208-
GUILayout.Space(Styles.BaseSpacing);
209211
GUILayout.EndVertical();
210212
}
211213

@@ -215,7 +217,7 @@ private void DoRequire2fa(string msg)
215217

216218
need2fa = true;
217219
errorMessage = msg;
218-
busy = false;
220+
isBusy = false;
219221
Redraw();
220222
}
221223

@@ -224,7 +226,7 @@ private void DoResult(bool success, string msg)
224226
Logger.Trace("DoResult - Success:{0} Message:\"{1}\"", success, msg);
225227

226228
errorMessage = msg;
227-
busy = false;
229+
isBusy = false;
228230

229231
if (success == true)
230232
{

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class BranchesView : Subview
1515
private const string ConfirmSwitchMessage = "Switch branch to {0}?";
1616
private const string ConfirmSwitchOK = "Switch";
1717
private const string ConfirmSwitchCancel = "Cancel";
18+
private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout";
19+
private const string ConfirmCheckoutBranchMessage = "Checkout branch {0} from {1}?";
20+
private const string ConfirmCheckoutBranchOK = "Checkout";
21+
private const string ConfirmCheckoutBranchCancel = "Cancel";
22+
private const string WarningCheckoutBranchExistsTitle = "Branch already exists";
23+
private const string WarningCheckoutBranchExistsMessage = "Branch {0} already exists";
24+
private const string WarningCheckoutBranchExistsOK = "Ok";
1825
private const string NewBranchCancelButton = "x";
1926
private const string NewBranchConfirmButton = "Create";
2027
private const string FavoritesSetting = "Favorites";
@@ -23,6 +30,10 @@ class BranchesView : Subview
2330
private const string LocalTitle = "Local branches";
2431
private const string RemoteTitle = "Remote branches";
2532
private const string CreateBranchButton = "New Branch";
33+
private const string DeleteBranchMessageFormatString = "Are you sure you want to delete the branch: {0}?";
34+
private const string DeleteBranchTitle = "Delete Branch?";
35+
private const string DeleteBranchButton = "Delete";
36+
private const string CancelButtonLabel = "Cancel";
2637

2738
private bool showLocalBranches = true;
2839
private bool showRemoteBranches = true;
@@ -147,7 +158,7 @@ public void OnEmbeddedGUI()
147158

148159
GUILayout.BeginHorizontal();
149160
{
150-
OnCreateGUI();
161+
OnButtonBarGUI();
151162
}
152163
GUILayout.EndHorizontal();
153164

@@ -308,6 +319,9 @@ private void OnRemoteBranchesUpdate(IEnumerable<GitBranch> list)
308319

309320
private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remote)
310321
{
322+
//Clear the selected node
323+
selectedNode = null;
324+
311325
// Sort
312326
var localBranches = new List<GitBranch>(local);
313327
var remoteBranches = new List<GitBranch>(remote);
@@ -451,28 +465,28 @@ private void SetFavourite(BranchTreeNode branch, bool favourite)
451465
}
452466
}
453467

454-
private void OnCreateGUI()
468+
private void OnButtonBarGUI()
455469
{
456-
// Create button
457470
if (mode == BranchesMode.Default)
458471
{
472+
// Delete button
459473
// If the current branch is selected, then do not enable the Delete button
460-
var disableDelete = activeBranchNode == selectedNode;
474+
var disableDelete = selectedNode == null || selectedNode.Type == NodeType.Folder || activeBranchNode == selectedNode;
461475
EditorGUI.BeginDisabledGroup(disableDelete);
462476
{
463-
if (GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
477+
if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
464478
{
465479
var selectedBranchName = selectedNode.Name;
466-
var dialogTitle = "Delete Branch: " + selectedBranchName;
467-
var dialogMessage = "Are you sure you want to delete the branch: " + selectedBranchName + "?";
468-
if (EditorUtility.DisplayDialog("Delete Branch?", dialogMessage, "Delete", "Cancel"))
480+
var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName);
481+
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
469482
{
470483
GitClient.DeleteBranch(selectedBranchName, true).Start();
471484
}
472485
}
473486
}
474487
EditorGUI.EndDisabledGroup();
475488

489+
// Create button
476490
GUILayout.FlexibleSpace();
477491
if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
478492
{
@@ -649,37 +663,62 @@ private void OnTreeNodeGUI(BranchTreeNode node)
649663

650664
if (Event.current.clickCount > 1 && mode == BranchesMode.Default)
651665
{
652-
if (node.Type == NodeType.LocalBranch &&
653-
EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK,
654-
ConfirmSwitchCancel))
666+
if (node.Type == NodeType.LocalBranch)
655667
{
656-
GitClient.SwitchBranch(node.Name)
657-
.FinallyInUI((success, e) =>
658-
{
659-
if (success)
660-
Refresh();
661-
else
668+
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK, ConfirmSwitchCancel))
669+
{
670+
GitClient.SwitchBranch(node.Name)
671+
.FinallyInUI((success, e) =>
662672
{
663-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
664-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
665-
Localization.Ok);
666-
}
667-
}).Start();
673+
if (success)
674+
{
675+
Refresh();
676+
}
677+
else
678+
{
679+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
680+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
681+
Localization.Ok);
682+
}
683+
}).Start();
684+
}
668685
}
669686
else if (node.Type == NodeType.RemoteBranch)
670687
{
671-
GitClient.CreateBranch(selectedNode.Name.Substring(selectedNode.Name.IndexOf('/') + 1), selectedNode.Name)
672-
.FinallyInUI((success, e) =>
688+
var indexOfFirstSlash = selectedNode.Name.IndexOf('/');
689+
var originName = selectedNode.Name.Substring(0, indexOfFirstSlash);
690+
var branchName = selectedNode.Name.Substring(indexOfFirstSlash + 1);
691+
692+
if (Repository.LocalBranches.Any(localBranch => localBranch.Name == branchName))
693+
{
694+
EditorUtility.DisplayDialog(WarningCheckoutBranchExistsTitle,
695+
String.Format(WarningCheckoutBranchExistsMessage, branchName),
696+
WarningCheckoutBranchExistsOK);
697+
}
698+
else
699+
{
700+
var confirmCheckout = EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle,
701+
String.Format(ConfirmCheckoutBranchMessage, node.Name, originName),
702+
ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel);
703+
704+
if (confirmCheckout)
673705
{
674-
if (success)
675-
Refresh();
676-
else
677-
{
678-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
679-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
680-
Localization.Ok);
681-
}
682-
}).Start();
706+
GitClient.CreateBranch(branchName, selectedNode.Name)
707+
.FinallyInUI((success, e) =>
708+
{
709+
if (success)
710+
{
711+
Refresh();
712+
}
713+
else
714+
{
715+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
716+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
717+
Localization.Ok);
718+
}
719+
}).Start();
720+
}
721+
}
683722
}
684723
}
685724
}

0 commit comments

Comments
 (0)