Skip to content

Commit 126b330

Browse files
committed
Fixed bug that would cause multiple of the same files to be shown.
repo title now shows branch you're on app logs get saved in Windows ProgramData can now create new branches the push to remotes auto refresh wont get stuck if creds arn't set up
1 parent a1fae71 commit 126b330

File tree

9 files changed

+159
-33
lines changed

9 files changed

+159
-33
lines changed

GitItGUI.Core/AppManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public static void SaveSettings()
215215
public static void Dispose()
216216
{
217217
RepoManager.Dispose();
218+
Debug.Dispose();
218219
}
219220

220221
public static bool CheckForUpdates(string url, string outOfDateURL, CheckForUpdatesCallbackMethod checkForUpdatesCallback)

GitItGUI.Core/BranchManager.cs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
namespace GitItGUI.Core
1111
{
12+
public class Remote
13+
{
14+
public string name, url;
15+
16+
public override string ToString()
17+
{
18+
return name;
19+
}
20+
}
21+
1222
public class BranchState
1323
{
1424
public Branch branch;
@@ -27,6 +37,7 @@ public static class BranchManager
2737
{
2838
public static Branch activeBranch;
2939
private static List<BranchState> allBranches;
40+
private static List<Remote> remotes;
3041

3142
internal static void OpenRepo(Repository repo)
3243
{
@@ -67,8 +78,14 @@ public static string GetTrackedBranchName()
6778
return activeBranch.TrackedBranch.FriendlyName;
6879
}
6980

81+
public static Remote[] GetRemotes()
82+
{
83+
return remotes.ToArray();
84+
}
85+
7086
internal static bool Refresh()
7187
{
88+
// gather branches
7289
if (allBranches == null) allBranches = new List<BranchState>();
7390
else allBranches.Clear();
7491

@@ -85,6 +102,22 @@ internal static bool Refresh()
85102
allBranches.Add(b);
86103
}
87104

105+
// gather remotes
106+
if (remotes == null) remotes = new List<Remote>();
107+
else remotes.Clear();
108+
109+
var allRemotes = RepoManager.repo.Network.Remotes;
110+
foreach (var remote in allRemotes)
111+
{
112+
var newRemote = new Remote()
113+
{
114+
name = remote.Name,
115+
url = remote.Url
116+
};
117+
118+
remotes.Add(newRemote);
119+
}
120+
88121
return true;
89122
}
90123

@@ -202,13 +235,37 @@ public static MergeResults MergeBranchIntoActive(BranchState srcBranch, StatusUp
202235
return mergeResult;
203236
}
204237

205-
public static bool AddNewBranch(string branchName)
238+
public static bool AddNewBranch(string branchName, string remoteName = null)
206239
{
240+
bool success = true;
241+
207242
try
208243
{
244+
// create branch
209245
var branch = RepoManager.repo.CreateBranch(branchName);
210246
Commands.Checkout(RepoManager.repo, branch);
211247
activeBranch = branch;
248+
249+
// push branch to remote
250+
if (!string.IsNullOrEmpty(remoteName))
251+
{
252+
// add remote
253+
RepoManager.repo.Branches.Update(activeBranch, b =>
254+
{
255+
b.Remote = remoteName;
256+
b.TrackedBranch = string.Format("refs/remotes/{0}/{1}", remoteName, branchName);
257+
b.UpstreamBranch = "refs/heads/" + branchName;
258+
});
259+
260+
// push remote
261+
string errors;
262+
string result = Tools.RunExeOutputErrors("git", string.Format("push -u {0} {1}", remoteName, branch.FriendlyName), null, out errors);
263+
if (!string.IsNullOrEmpty(errors) && !errors.Contains("To create a merge request for"))//NOTE: this ignores false positive noise errors that come from GitLab
264+
{
265+
Debug.LogError("Push remote failed: " + errors, true);
266+
success = false;
267+
}
268+
}
212269
}
213270
catch (Exception e)
214271
{
@@ -217,7 +274,7 @@ public static bool AddNewBranch(string branchName)
217274
}
218275

219276
RepoManager.Refresh();
220-
return true;
277+
return success;
221278
}
222279

223280
public static bool DeleteNonActiveBranch(BranchState branch)
@@ -257,12 +314,12 @@ public static bool RenameActiveBranch(string newBranchName)
257314
return true;
258315
}
259316

260-
public static bool AddUpdateTracking(BranchState srcRemoteBranch)
317+
public static bool CopyTracking(BranchState srcRemoteBranch)
261318
{
262-
return AddUpdateTracking(srcRemoteBranch.fullName);
319+
return CopyTracking(srcRemoteBranch.fullName);
263320
}
264321

265-
public static bool AddUpdateTracking(string srcRemoteBranch)
322+
public static bool CopyTracking(string srcRemoteBranch)
266323
{
267324
try
268325
{

GitItGUI.Core/Tools/Debug.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23

34
namespace GitItGUI.Core
45
{
@@ -16,21 +17,56 @@ public static class Debug
1617
/// </summary>
1718
public static event DebugLogCallbackMethod debugLogCallback, debugLogWarningCallback, debugLogErrorCallback;
1819

20+
private static Stream stream;
21+
private static StreamWriter writer;
22+
23+
static Debug()
24+
{
25+
try
26+
{
27+
string logFileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
28+
logFileName += "\\" + Settings.appSettingsFolderName + "\\" + "logs.txt";
29+
stream = new FileStream(logFileName, FileMode.Create, FileAccess.Write, FileShare.None);
30+
writer = new StreamWriter(stream);
31+
}
32+
catch (Exception e)
33+
{
34+
LogError("Failed to init debug log file: " + e.Message);
35+
}
36+
}
37+
38+
internal static void Dispose()
39+
{
40+
if (stream != null)
41+
{
42+
writer.Flush();
43+
stream.Flush();
44+
stream.Dispose();
45+
stream = null;
46+
}
47+
}
48+
1949
public static void Log(object value, bool alert = false)
2050
{
21-
Console.WriteLine("GitItGUI.Core Log: " + value.ToString());
51+
string msg = value.ToString();
52+
Console.WriteLine(msg);
53+
if (writer != null) writer.WriteLine(msg);
2254
if (debugLogCallback != null) debugLogCallback(value, alert);
2355
}
2456

2557
public static void LogWarning(object value, bool alert = false)
2658
{
27-
Console.WriteLine("GitItGUI.Core Log WARNING: " + value.ToString());
59+
string msg = "WARNING: " + value.ToString();
60+
Console.WriteLine(msg);
61+
if (writer != null) writer.WriteLine(msg);
2862
if (debugLogWarningCallback != null) debugLogWarningCallback(value, alert);
2963
}
3064

3165
public static void LogError(object value, bool alert = false)
3266
{
33-
Console.WriteLine("GitItGUI.Core Log ERROR: " + value.ToString());
67+
string msg = "ERROR: " + value.ToString();
68+
Console.WriteLine(msg);
69+
if (writer != null) writer.WriteLine(msg);
3470
if (debugLogErrorCallback != null) debugLogErrorCallback(value, alert);
3571
}
3672
}

GitItGUI/BranchesPage.xaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl xmlns="https://github.com/avaloniaui" Design.Width="800" Design.Height="400" xmlns:self="clr-namespace:GitItGUI;assembly=GitItGUI">
1+
<UserControl xmlns="https://github.com/avaloniaui" Design.Width="1280" Design.Height="800" xmlns:self="clr-namespace:GitItGUI;assembly=GitItGUI">
22
<Grid>
33
<Grid.ColumnDefinitions>
44
<ColumnDefinition Width="50*" />
@@ -9,17 +9,20 @@
99
<TextBlock FontSize="24" Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">Active Branch</TextBlock>
1010
<TextBlock Height="32" Margin="10,50,10,-50" TextAlignment="Right" HorizontalAlignment="Left" VerticalAlignment="Top">Branch Name:</TextBlock>
1111
<TextBox Name="activeBranchTextBox" Height="32" Margin="100,50,0,-50" VerticalAlignment="Top" Background="White" IsReadOnly="True" ToolTip.Tip="Current 'Active' branch name"/>
12-
<Button Name="addBranchButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,85,-100,10" Width="75" ToolTip.Tip="Add new branch based off 'Active'?">Add</Button>
13-
<Button Name="renameBranchButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="180,85,-180,10" Width="75" ToolTip.Tip="Rename 'Active' branch?">Rename</Button>
12+
<Button Name="renameBranchButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,85,-100,10" Width="75" ToolTip.Tip="Rename 'Active' branch?">Rename</Button>
1413

1514
<TextBlock Name="trackingLabel" FontSize="18" Margin="0,150,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">--- Tracking ---</TextBlock>
1615
<TextBlock Name="trackedBranchLabel" Width="82" Height="32" Margin="10,180,10,-180" TextAlignment="Right" HorizontalAlignment="Left" VerticalAlignment="Top">Tracked Branch:</TextBlock>
1716
<TextBox Name="trackingOriginTextBox" Height="32" Margin="100,180,0,-50" VerticalAlignment="Top" Background="White" IsReadOnly="True" ToolTip.Tip="Active branch tracking origin"/>
1817
<TextBlock Name="remoteURLLabel" Width="82" Height="32" Margin="10,215,10,-215" TextAlignment="Right" HorizontalAlignment="Left" VerticalAlignment="Top">Remote URL:</TextBlock>
1918
<TextBox Name="remoteURLTextBox" Height="32" Margin="100,215,0,-50" VerticalAlignment="Top" Background="White" IsReadOnly="True" ToolTip.Tip="Active branch tracking origin"/>
20-
<Button Name="addTrackingButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,250,-100,-250" Width="75" ToolTip.Tip="Copy tracking from 'Other' remote branch into 'Active'">*Add</Button>
19+
<Button Name="copyTrackingButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,250,-100,-250" Width="75" ToolTip.Tip="Copy tracking from 'Other' remote branch into 'Active' branch">Copy</Button>
2120
<Button Name="removeTrackingButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="180,250,-180,-250" Width="75" ToolTip.Tip="Remove tracking from 'Active' branch">Remove</Button>
2221

22+
<TextBlock Name="newBranchLabel" FontSize="18" Margin="0,320,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">--- Create New Branch ---</TextBlock>
23+
<Button Name="addBranchButton" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,360,-100,-360" Width="75" ToolTip.Tip="Add new branch based off 'Active'?">Add</Button>
24+
<DropDown Name="remotesDropDown" VerticalAlignment="Top" Margin="180,360,0,-360" Height="28" ToolTip.Tip="Rename 'Active' branch?"/>
25+
2326
<CheckBox Name="advancedModeCheckBox" Margin="10" HorizontalContentAlignment="Left" VerticalAlignment="Bottom">Advanced Mode</CheckBox>
2427
</Grid>
2528

GitItGUI/BranchesPage.xaml.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ public class BranchesPage : UserControl
1717
public static BranchesPage singleton;
1818

1919
// ui objects
20-
TextBlock trackingLabel, trackedBranchLabel, remoteURLLabel;
20+
TextBlock trackingLabel, trackedBranchLabel, remoteURLLabel, newBranchLabel;
2121
TextBox activeBranchTextBox, trackingOriginTextBox, remoteURLTextBox;
2222
ListBox otherBranchListView;
23-
Button addBranchButton, renameBranchButton, addTrackingButton, removeTrackingButton, switchBranchButton, mergeBranchButton, deleteBranchButton;
23+
Button addBranchButton, renameBranchButton, copyTrackingButton, removeTrackingButton, switchBranchButton, mergeBranchButton, deleteBranchButton;
2424
CheckBox advancedModeCheckBox;
25+
DropDown remotesDropDown;
2526

2627
List<string> otherBranchListViewItems;
2728

@@ -37,7 +38,7 @@ public BranchesPage()
3738
otherBranchListView = this.Find<ListBox>("otherBranchListView");
3839
addBranchButton = this.Find<Button>("addBranchButton");
3940
renameBranchButton = this.Find<Button>("renameBranchButton");
40-
addTrackingButton = this.Find<Button>("addTrackingButton");
41+
copyTrackingButton = this.Find<Button>("copyTrackingButton");
4142
removeTrackingButton = this.Find<Button>("removeTrackingButton");
4243
switchBranchButton = this.Find<Button>("switchBranchButton");
4344
mergeBranchButton = this.Find<Button>("mergeBranchButton");
@@ -46,13 +47,15 @@ public BranchesPage()
4647
trackingLabel = this.Find<TextBlock>("trackingLabel");
4748
trackedBranchLabel = this.Find<TextBlock>("trackedBranchLabel");
4849
remoteURLLabel = this.Find<TextBlock>("remoteURLLabel");
50+
newBranchLabel = this.Find<TextBlock>("newBranchLabel");
51+
remotesDropDown = this.Find<DropDown>("remotesDropDown");
4952

5053
// apply bindings
5154
otherBranchListViewItems = new List<string>();
5255
otherBranchListView.Items = otherBranchListViewItems;
5356
addBranchButton.Click += AddBranchButton_Click;
5457
renameBranchButton.Click += RenameBranchButton_Click;
55-
addTrackingButton.Click += AddTrackingButton_Click;
58+
copyTrackingButton.Click += CopyTrackingButton_Click;
5659
removeTrackingButton.Click += RemoveTrackingButton_Click;
5760
switchBranchButton.Click += SwitchBranchButton_Click;
5861
mergeBranchButton.Click += MergeBranchButton_Click;
@@ -65,7 +68,7 @@ public BranchesPage()
6568

6669
private void AdvancedModeCheckBox_Click(object sender, RoutedEventArgs e)
6770
{
68-
RepoManager_RepoRefreshedCallback();
71+
RepoManager_RepoRefreshedCallback_UIThread();
6972
}
7073

7174
private void RepoManager_RepoRefreshedCallback()
@@ -96,11 +99,24 @@ private void RepoManager_RepoRefreshedCallback_UIThread()
9699
renameBranchButton.IsVisible = isAdvancedMode;
97100
trackingOriginTextBox.IsVisible = isAdvancedMode;
98101
remoteURLTextBox.IsVisible = isAdvancedMode;
99-
addTrackingButton.IsVisible = isAdvancedMode;
102+
copyTrackingButton.IsVisible = isAdvancedMode;
100103
removeTrackingButton.IsVisible = isAdvancedMode;
101104
trackingLabel.IsVisible = isAdvancedMode;
102105
trackedBranchLabel.IsVisible = isAdvancedMode;
103106
remoteURLLabel.IsVisible = isAdvancedMode;
107+
newBranchLabel.IsVisible = isAdvancedMode;
108+
remotesDropDown.IsVisible = isAdvancedMode;
109+
110+
// fill remotes drop down
111+
if (isAdvancedMode)
112+
{
113+
var remotes = new List<Core.Remote>();
114+
var localRemote = new Core.Remote() {name = "N/A - LOCAL ONLY"};
115+
remotes.Add(localRemote);
116+
remotes.AddRange(BranchManager.GetRemotes());
117+
remotesDropDown.Items = remotes;
118+
remotesDropDown.SelectedIndex = 0;
119+
}
104120

105121
// fill other branches list
106122
var branches = BranchManager.GetOtherBranches(isAdvancedMode);
@@ -130,8 +146,18 @@ private void RepoManager_RepoRefreshedCallback_UIThread()
130146

131147
private void AddBranchButton_Click(object sender, RoutedEventArgs e)
132148
{
149+
if (remotesDropDown.SelectedItem == null)
150+
{
151+
Debug.LogError("Must select remote!", true);
152+
return;
153+
}
154+
155+
var remote = (Core.Remote)remotesDropDown.SelectedItem;
156+
string remoteName = remote.name;
157+
if (remote.url == null) remoteName = null;
158+
133159
string result;
134-
if (CoreApps.LaunchNameEntry("Enter branch name", out result)) BranchManager.AddNewBranch(result);
160+
if (CoreApps.LaunchNameEntry("Enter branch name", out result)) BranchManager.AddNewBranch(result, remoteName);
135161
}
136162

137163
private void RenameBranchButton_Click(object sender, RoutedEventArgs e)
@@ -140,7 +166,7 @@ private void RenameBranchButton_Click(object sender, RoutedEventArgs e)
140166
if (CoreApps.LaunchNameEntry("Enter branch name", out result)) BranchManager.RenameActiveBranch(result);
141167
}
142168

143-
private void AddTrackingButton_Click(object sender, RoutedEventArgs e)
169+
private void CopyTrackingButton_Click(object sender, RoutedEventArgs e)
144170
{
145171
if (otherBranchListView.SelectedIndex == -1)
146172
{
@@ -155,7 +181,7 @@ private void AddTrackingButton_Click(object sender, RoutedEventArgs e)
155181
return;
156182
}
157183

158-
BranchManager.AddUpdateTracking(branch);
184+
BranchManager.CopyTracking(branch);
159185
}
160186

161187
private void RemoveTrackingButton_Click(object sender, RoutedEventArgs e)

GitItGUI/ChangesPage.xaml.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,30 +406,31 @@ private bool ChangesManager_AskUserIfTheyAcceptMergedFileCallback(FileState file
406406
return true;
407407
}
408408

409-
private void CheckLocalBranchSyncErrors()
409+
private bool CheckLocalBranchSyncErrors()
410410
{
411-
if (BranchManager.IsTracking()) return;
412-
411+
if (BranchManager.IsTracking()) return true;
413412

413+
MessageBox.Show("Local Branch is not tracking a remote!\nPlease use 'advanced' features in the Branch tab to fix.");
414+
return false;
414415
}
415416

416417
private void PushChangesButton_Advanced_Click(object sender, RoutedEventArgs e)
417418
{
418-
CheckLocalBranchSyncErrors();
419+
if (!CheckLocalBranchSyncErrors()) return;
419420
ProcessingPage.singleton.mode = ProcessingPageModes.Push;
420421
MainWindow.LoadPage(PageTypes.Processing);
421422
}
422423

423424
private void PullChangesButton_Advanced_Click(object sender, RoutedEventArgs e)
424425
{
425-
CheckLocalBranchSyncErrors();
426+
if (!CheckLocalBranchSyncErrors()) return;
426427
ProcessingPage.singleton.mode = ProcessingPageModes.Pull;
427428
MainWindow.LoadPage(PageTypes.Processing);
428429
}
429430

430431
private void SyncChangesButton_Click(object sender, RoutedEventArgs e)
431432
{
432-
CheckLocalBranchSyncErrors();
433+
if (!CheckLocalBranchSyncErrors()) return;
433434

434435
// check if files need to be staged
435436
if (ChangesManager.FilesAreUnstaged())

GitItGUI/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public MainWindow()
3030
AvaloniaXamlLoader.Load(this);
3131
App.AttachDevTools(this);
3232
Title = "Git-It-GUI v" + VersionInfo.version;
33+
Debug.Log(Title);
3334

3435
// load resources
3536
ResourceManager.Init();

0 commit comments

Comments
 (0)