Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

#11 - .git directory handling #15

Merged
merged 2 commits into from

2 participants

@ChrisWay

Added handling if the user selects a .git directory and also default to the user's My Documents folder when first choosing "Browse Repository".

How should the case be handled if the user selects a non git directory (so monitoring is started), changes to a .git directory and then creates a git repo in the original dir that is being monitored? Currently the graph will switch back the monitored dir, not likely to happen but you never know! Should the monitoring be aborted when choosing an existing git repo or is the current behavior correct?

ChrisWay added some commits
@ChrisWay ChrisWay #11 - Added handling for when passed a .git directory. Also default d…
…irectory picker to the user's My Documents folder.
9fab7d0
@ChrisWay ChrisWay Made sure the last directory the user selected is remembered and set …
…to the starting one if they browse for another repository.
e9b0d75
@Haacked Haacked commented on the diff
SeeGitApp/Extensions/ModelExtensions.cs
@@ -20,11 +20,12 @@ public static string NormalizeGitRepositoryPath(this string path)
{
if (path == null) throw new ArgumentNullException("path");
- var folderName = Path.GetDirectoryName(path) ?? "";
- if (folderName.Equals(".git", StringComparison.OrdinalIgnoreCase))
+ //If we are passed a .git directory, just return it straightaway
+ if (path.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
@Haacked Owner
Haacked added a note

Probably better to use the path methods here. For example, in theory it could get a path with a trailing slash (though not sure if that'll actually happen).

Path.GetFolderName(path)

Or something like that should do the trick. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Haacked
Owner

Apart from the one change I suggested, this looks great. Thanks! I'm going to merge it in now anyways.

@Haacked Haacked merged commit b413038 into Haacked:master
@Haacked
Owner

I forgot to comment on your question. If I understand correctly, the sequence is:

  1. Open up c:\foo which does not contain a git repo.
  2. Then use the file browser to select c:\bar\ which does have a git directory.
  3. Then runs git init in c:\foo and SeeGit starts monitoring c:\foo again?

If so, that's definitely a bug. When we use the folder browser to select a folder, we should dispose all previous file monitors.

@ChrisWay

Thanks Phil, I'll make that change tonight and that sequence is correct. Presumably to cancel the file monitors you need to hold on to the IDisposable that is returned from Subscribe and then call Dispose?

@Haacked
Owner
@ChrisWay ChrisWay referenced this pull request from a commit in ChrisWay/SeeGit
@ChrisWay ChrisWay Changed the directory handling slightly as mentioned in the comments on
#15. Using DirectoryInfo as Path doesn't have a simple way of grabbing the last dir in a path.
224ff70
@ChrisWay ChrisWay referenced this pull request from a commit in ChrisWay/SeeGit
@ChrisWay ChrisWay Implemented cancelling of repository watching if the user selects a d…
…ifferent directory as per discussion in #15.
a27a817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 19, 2012
  1. @ChrisWay

    #11 - Added handling for when passed a .git directory. Also default d…

    ChrisWay authored
    …irectory picker to the user's My Documents folder.
  2. @ChrisWay

    Made sure the last directory the user selected is remembered and set …

    ChrisWay authored
    …to the starting one if they browse for another repository.
This page is out of date. Refresh to see the latest.
View
5 SeeGitApp/Extensions/ModelExtensions.cs
@@ -20,11 +20,12 @@ public static string NormalizeGitRepositoryPath(this string path)
{
if (path == null) throw new ArgumentNullException("path");
- var folderName = Path.GetDirectoryName(path) ?? "";
- if (folderName.Equals(".git", StringComparison.OrdinalIgnoreCase))
+ //If we are passed a .git directory, just return it straightaway
+ if (path.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
@Haacked Owner
Haacked added a note

Probably better to use the path methods here. For example, in theory it could get a path with a trailing slash (though not sure if that'll actually happen).

Path.GetFolderName(path)

Or something like that should do the trick. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
{
return path;
}
+
return Path.Combine(path, ".git");
}
View
12 SeeGitApp/Extensions/WindowsExtensions.cs
@@ -1,18 +1,24 @@
-using Microsoft.WindowsAPICodePack.Dialogs;
+using System.IO;
+using Microsoft.WindowsAPICodePack.Dialogs;
namespace SeeGit
{
public static class WindowsExtensions
{
+ private static string _lastDirectory;
+
public static string BrowseForFolder(string startingPath)
{
var cfd = new CommonOpenFileDialog
{
- DefaultFileName = startingPath,
+ InitialDirectory = _lastDirectory ?? startingPath,
IsFolderPicker = true,
};
- if (cfd.ShowDialog() != CommonFileDialogResult.Ok) return null;
+ if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
+ _lastDirectory = Path.GetDirectoryName(cfd.FileName);
+ else
+ return null;
var ret = cfd.FileName;
return ret;
View
5 SeeGitApp/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using System;
+using System.Windows;
namespace SeeGit
{
@@ -14,7 +15,7 @@ public MainWindow()
private void OnChooseRepository(object sender, RoutedEventArgs args)
{
- _viewModel.MonitorRepository(WindowsExtensions.BrowseForFolder(@"c:\dev\exp\empty"));
+ _viewModel.MonitorRepository(WindowsExtensions.BrowseForFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
}
}
}
Something went wrong with that request. Please try again.