New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show current work dir at startup if it is in a git rep #23

Merged
merged 2 commits into from Mar 23, 2012
Jump to file or symbol
Failed to load files and symbols.
+29 −3
Diff settings

Always

Just for now

@@ -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

This comment has been minimized.

@Haacked

Haacked Mar 23, 2012

Owner

Good point! We should never get an invalid path. Probably should throw an exception. Later on, we need to add in some global exception handling. But for now, I'm fine with crashing the app if you pass us an invalid path. :)

@Haacked

Haacked Mar 23, 2012

Owner

Good point! We should never get an invalid path. Probably should throw an exception. Later on, we need to add in some global exception handling. But for now, I'm fine with crashing the app if you pass us an invalid path. :)

// 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;

This comment has been minimized.

@Haacked

Haacked Mar 23, 2012

Owner

Actually, it's ok if we're returning the original path here. Notice in MainWindowViewModel.cs line 53 if the directory you give us is not a .git directory and doesn't have a .git directory, we monitor the directory waiting for you to create one in there.

In my demos, I start monitoring an empty directory. Then I create a git repo in there and add commits and SeeGit automatically comes alive showing the commit graph. :)

@Haacked

Haacked Mar 23, 2012

Owner

Actually, it's ok if we're returning the original path here. Notice in MainWindowViewModel.cs line 53 if the directory you give us is not a .git directory and doesn't have a .git directory, we monitor the directory waiting for you to create one in there.

In my demos, I start monitoring an empty directory. Then I create a git repo in there and add commits and SeeGit automatically comes alive showing the commit graph. :)

This comment has been minimized.

@davidanthoff

davidanthoff Mar 23, 2012

Contributor

Ah, I didn't think about the case where you want to actually point to an empty directory, but it makes sense and I think the code should work for that as well.

@davidanthoff

davidanthoff Mar 23, 2012

Contributor

Ah, I didn't think about the case where you want to actually point to an empty directory, but it makes sense and I think the code should work for that as well.

}
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);
ProTip! Use n and p to navigate between commits in a pull request.