Permalink
Browse files

Merge pull request #23 from davidanthoff/findgitpath

Show current work dir at startup if it is in a git rep
  • Loading branch information...
2 parents 5bd9081 + a4438ec commit fa19466b536e590d300d224f3fa7bb0cf38fc8ba @Haacked committed Mar 23, 2012
@@ -16,17 +16,40 @@ public static string AtMost(this string s, int characterCount)
return s.Substring(0, characterCount);
}
- public static string NormalizeGitRepositoryPath(this string path)
+ public static string GetGitRepositoryPath(string path)
{
if (path == null) throw new ArgumentNullException("path");
+ // This is not good, it relies on the rest of the code being ok
+ // with getting a path that doesn't exist
+ if (!Directory.Exists(path)) return path;
+
//If we are passed a .git directory, just return it straightaway
if (path.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
{
return path;
}
- return Path.Combine(path, ".git");
+ string subfolderToFind = ".git";
+
+ DirectoryInfo checkIn = new DirectoryInfo(path);
+
+ while (checkIn != null)
+ {
+ string pathToTest = Path.Combine(checkIn.FullName, subfolderToFind);
+ if (Directory.Exists(pathToTest))
+ {
+ return pathToTest;
+ }
+ else
+ {
+ checkIn = checkIn.Parent;
+ }
+ }
+
+ // This is not good, it relies on the rest of the code being ok
+ // with getting a non-git repo dir
+ return path;
}
public static IObservable<FileSystemEventArgs> CreateGitRepositoryCreationObservable(string path)
@@ -1,5 +1,6 @@
using System;
using System.Windows;
+using System.IO;
namespace SeeGit
{
@@ -11,6 +12,8 @@ public MainWindow()
{
InitializeComponent();
DataContext = _viewModel = new MainWindowViewModel(Dispatcher, path => new RepositoryGraphBuilder(path));
+
+ _viewModel.MonitorRepository(Directory.GetCurrentDirectory());
}
private void OnChooseRepository(object sender, RoutedEventArgs args)
@@ -47,7 +47,7 @@ public RepositoryGraph Graph
public void MonitorRepository(string repositoryWorkingPath)
{
if (repositoryWorkingPath == null) return;
- string gitPath = repositoryWorkingPath.NormalizeGitRepositoryPath();
+ string gitPath = ModelExtensions.GetGitRepositoryPath(repositoryWorkingPath);
if (!Directory.Exists(gitPath))
{
MonitorForRepositoryCreation(repositoryWorkingPath);

0 comments on commit fa19466

Please sign in to comment.