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.
+26 −3
Diff settings

Always

Just for now

Next

Make function that looks for git rep recursive

With this patch one can specify any folder in a git working directory and
the code will find the .git directory relevant for that working directory,
even if one picked a sub directory.
  • Loading branch information...
davidanthoff committed Mar 22, 2012
commit 2514add86fb94c412815dbc36e3f6c29e4f45467
@@ -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)
@@ -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.