Skip to content

Commit

Permalink
Small cleanup items based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbaker committed Aug 22, 2019
1 parent 177c631 commit 222cfde
Showing 1 changed file with 11 additions and 54 deletions.
65 changes: 11 additions & 54 deletions Scalar/CommandLine/SparseVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Scalar.Common.Http;
using Scalar.Common.Tracing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -56,13 +57,7 @@ protected override void Execute(ScalarEnlistment enlistment)
{ nameof(this.Add), this.Add },
});

// Make sure there is a clean git status before allowing sparse set to change
this.CheckGitStatus(tracer, enlistment);

string[] foldersToAdd = this.ParseFolderList(this.Add);

// TODO: Compare foldersToAdd with `git sparse-checkout list` to determine if anything new is
// being added
List<string> foldersToAdd = this.ParseFolderList(this.Add);

// Pre-fetch the blobs for the folders that will be added
ReturnCode result = this.Execute<PrefetchVerb>(
Expand All @@ -82,33 +77,35 @@ protected override void Execute(ScalarEnlistment enlistment)

this.SparseCheckoutAdd(tracer, enlistment, foldersToAdd);
}
catch (Exception e) when (!(e is VerbAbortedException))
catch (Exception e)
{
this.ReportErrorAndExit(tracer, e.ToString());
this.ReportErrorAndExit(tracer, "Failed to add folders to sparse-checkout {0}", e.Message);
}
}
}

private static string NormalizePath(string path)
{
return path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim().Trim(Path.DirectorySeparatorChar);
return path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
.Trim()
.Trim(Path.DirectorySeparatorChar);
}

private string[] ParseFolderList(string folders)
private List<string> ParseFolderList(string folders)
{
if (string.IsNullOrEmpty(folders))
{
return new string[0];
return new List<string>();
}
else
{
return folders.Split(new[] { FolderListSeparator }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => NormalizePath(x))
.ToArray();
.ToList();
}
}

private void SparseCheckoutAdd(ITracer tracer, ScalarEnlistment enlistment, string[] foldersToAdd)
private void SparseCheckoutAdd(ITracer tracer, ScalarEnlistment enlistment, List<string> foldersToAdd)
{
// TODO: Perform the `git sparse-checkout add`

Expand All @@ -132,46 +129,6 @@ private void SparseCheckoutAdd(ITracer tracer, ScalarEnlistment enlistment, stri
*/
}

private void CheckGitStatus(ITracer tracer, ScalarEnlistment enlistment)
{
GitProcess.Result statusResult = null;
if (!this.ShowStatusWhileRunning(
() =>
{
GitProcess git = new GitProcess(enlistment);
statusResult = git.Status(allowObjectDownloads: false, useStatusCache: false, showUntracked: true);
if (statusResult.ExitCodeIsFailure)
{
return false;
}
if (!statusResult.Output.Contains("nothing to commit, working tree clean"))
{
return false;
}
return true;
},
"Running git status",
suppressGvfsLogMessage: true))
{
this.Output.WriteLine();

if (statusResult.ExitCodeIsFailure)
{
this.WriteMessage(tracer, "Failed to run git status: " + statusResult.Errors);
}
else
{
this.WriteMessage(tracer, statusResult.Output);
this.WriteMessage(tracer, "git status reported that you have dirty files");
this.WriteMessage(tracer, "Either commit your changes or reset and clean");
}

this.ReportErrorAndExit(tracer, SparseVerbName + " was aborted");
}
}

private void WriteMessage(ITracer tracer, string message)
{
this.Output.WriteLine(message);
Expand Down

0 comments on commit 222cfde

Please sign in to comment.