-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fixing up the git support #20
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using System.Net; | ||
|
||
namespace warmup.infrastructure | ||
{ | ||
public static class Verifier | ||
{ | ||
|
||
|
||
public static string TestPath(string path) | ||
{ | ||
return new Uri(path).IsFile | ||
? Directory.Exists(path) | ||
? path | ||
: AdjustedPath(path) | ||
: isValid(path) | ||
? path | ||
: AdjustedPath(path); | ||
} | ||
|
||
public static string AdjustedPath(string path) | ||
{ | ||
return path.EndsWith(".git") | ||
? path | ||
: path + ".git"; | ||
} | ||
|
||
public static bool isValid(string url) | ||
{ | ||
try | ||
{ | ||
var urlReq = (HttpWebRequest)WebRequest.Create(url); | ||
var urlRes = (HttpWebResponse)urlReq.GetResponse(); | ||
var sStream = urlRes.GetResponseStream(); | ||
|
||
string read = new StreamReader(sStream).ReadToEnd(); | ||
return true; | ||
|
||
} | ||
catch (Exception) | ||
{ | ||
//Url not valid | ||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space is no |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,94 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using warmup.infrastructure.extractors; | ||
using warmup.infrastructure.settings; | ||
using System.IO; | ||
using System.Net; | ||
|
||
namespace warmup.infrastructure.exporters | ||
{ | ||
public class Git : BaseExporter | ||
{ | ||
public static void Clone(Uri sourceLocation, TargetDir target) | ||
public override void Export(string sourceControlWarmupLocation, string templateName, TargetDir targetDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So there is an export then? |
||
{ | ||
var separationCharacters = new[] {".git"}; | ||
string[] piecesOfPath = sourceLocation.ToString().Split(separationCharacters, StringSplitOptions.RemoveEmptyEntries); | ||
if (piecesOfPath != null && piecesOfPath.Length > 0) | ||
var gitsrc = (new Uri(sourceControlWarmupLocation)).IsFile | ||
? Path.Combine(sourceControlWarmupLocation, templateName) | ||
: NewUri(sourceControlWarmupLocation, templateName).AbsoluteUri; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really a fan of this. For instance, the terminator is not on its own line. but more in that I don't see this to be "that" long that it shouldn't all be on the same line. This goes for the others that you set up this way as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to write in a pointfree style where I can, and will avoid assignment where I can, as mutable values are a source of bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, not sure if we already have a common pattern in here for this or not. If we do I prefer it followed, no matter what the personal preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the GitHub URI would differ and it doesn't appear you are accounting for that. For instance, I am going to put in the URL https://github.com/ferventcoder/warmup-templates.git. That is the repo location.
How is that going to translate to https:// github.com/ferventcoder/warmup-templates/**tree/master/**base (space added for bolding)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, nevermind. You are still cloning the entire repository. I thought we were getting something awesome like svnexport where it just downloads only the pieces that you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although rereading your comments I'm not sure you understood what I meant... var gitsrc = (new Uri(sourceControlWarmupLocation)).IsFile
? Path.Combine(sourceControlWarmupLocation, templateName)
: NewUri(sourceControlWarmupLocation, templateName).AbsoluteUri; Should be like this: var gitsrc = (new Uri(sourceControlWarmupLocation)).IsFile ? Path.Combine(sourceControlWarmupLocation, templateName) : NewUri(sourceControlWarmupLocation, templateName).AbsoluteUri; Yes, I'm literally being terse on line breaks ;) |
||
|
||
var destination = targetDir == null | ||
? new TargetDir(Environment.CurrentDirectory) | ||
: targetDir; | ||
|
||
var gitSrcPath = Verifier.TestPath(gitsrc); | ||
|
||
var psi = new ProcessStartInfo("cmd", string.Format(" /c git clone {0} {1}", gitSrcPath, destination.FullPath)); | ||
|
||
psi.UseShellExecute = false; | ||
psi.CreateNoWindow = true; | ||
psi.RedirectStandardOutput = true; | ||
psi.RedirectStandardError = true; | ||
|
||
//todo: better error handling | ||
Console.WriteLine("Running: {0} {1}", psi.FileName, psi.Arguments); | ||
string output, error = ""; | ||
using (Process p = Process.Start(psi)) | ||
{ | ||
string sourceLocationToGit = piecesOfPath[0] + ".git"; | ||
output = p.StandardOutput.ReadToEnd(); | ||
error = p.StandardError.ReadToEnd(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are cleaning this up, let's not put the execution stuff in here. It should be in its own separate static class and method called from here. See https://github.com/chucknorris/roundhouse/blob/master/product/roundhouse/consoles/CommandExecutor.cs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be used as an example. I have a couple of additions in the way that I would have it run but I don't have them in a non-private repository at the moment. The point is, if you are going to redirect output, you should capture the messages in real time and output them to the console instead of logging it all at once after the fact. |
||
|
||
RemoveGitConfig(destination); | ||
|
||
Console.WriteLine(output); | ||
Console.WriteLine(error); | ||
|
||
var psi = new ProcessStartInfo("cmd",string.Format(" /c git clone {0} {1}", sourceLocationToGit, target.FullPath)); | ||
} | ||
|
||
psi.UseShellExecute = false; | ||
psi.CreateNoWindow = true; | ||
psi.RedirectStandardOutput = true; | ||
psi.RedirectStandardError = true; | ||
private static void RemoveGitConfig(TargetDir destination) | ||
{ | ||
Directory.Delete(path: Path.Combine(destination.FullPath, ".git"), recursive: true); | ||
} | ||
|
||
//todo: better error handling | ||
Console.WriteLine("Running: {0} {1}", psi.FileName, psi.Arguments); | ||
string output, error = ""; | ||
using (Process p = Process.Start(psi)) | ||
private static Uri NewUri(string baseUri, string relativeUri) | ||
{ | ||
var r = CreateUri(baseUri, relativeUri); | ||
if (r.Item1) | ||
{ | ||
return r.Item2; | ||
} | ||
else | ||
{ | ||
r = CreateUri(baseUri, ""); | ||
if (r.Item1) | ||
{ | ||
output = p.StandardOutput.ReadToEnd(); | ||
error = p.StandardError.ReadToEnd(); | ||
return r.Item2; | ||
} | ||
else | ||
{ | ||
throw new ArgumentException("The base is not valid"); | ||
} | ||
|
||
Console.WriteLine(output); | ||
Console.WriteLine(error); | ||
|
||
var templateName = piecesOfPath[1]; | ||
GitTemplateExtractor extractor = new GitTemplateExtractor(target, templateName); | ||
extractor.Extract(); | ||
//string git_directory = Path.Combine(target.FullPath, ".git"); | ||
//if (Directory.Exists(git_directory)) | ||
//{ | ||
// Console.WriteLine("Deleting {0} directory", git_directory); | ||
// Directory.Delete(git_directory, true); | ||
//} | ||
} | ||
} | ||
|
||
public override void Export(string sourceControlWarmupLocation, string templateName, TargetDir targetDir) | ||
private static Tuple<bool, Uri> CreateUri(string baseUri, string relativeUri) | ||
{ | ||
var baseUri = new Uri(WarmupConfiguration.settings.SourceControlWarmupLocation + templateName); | ||
Console.WriteLine("git exporting to: {0}", targetDir.FullPath); | ||
Clone(baseUri, targetDir); | ||
return CreateUri( | ||
baseUri.EndsWith("/") | ||
? new Uri(baseUri) | ||
: new Uri(baseUri + "/"), | ||
relativeUri); | ||
} | ||
|
||
private static Tuple<bool,Uri> CreateUri(Uri baseUri, string relativeUri) { | ||
Uri ret; | ||
return Tuple.Create(Uri.TryCreate(baseUri, relativeUri, out ret), ret); | ||
} | ||
|
||
//public static void Clone(Uri sourceLocation, TargetDir target) | ||
//{ | ||
//} | ||
|
||
//public static void Clone(string sourceLocation, TargetDir target) | ||
//{ | ||
//} | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up the spacing above this