Skip to content
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

Allow repositories without an 'origin' remote #353

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Scalar.Common/Enlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ protected Enlistment(
GitProcess.ConfigResult originResult = gitProcess.GetOriginUrl();
if (!originResult.TryParseAsString(out string originUrl, out string error))
{
throw new InvalidRepoException(this.WorkingDirectoryRoot, "Could not get origin url. git error: " + error);
if (!gitProcess.TryGetRemotes(out string[] remotes, out error))
{
throw new InvalidRepoException(this.WorkingDirectoryRoot, $"Failed to load remotes with error: {error}");
}

if (remotes.Length > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be remotes.Length == 1? If there are more that one are we sure we are doing the right thing to just take the first remote? Should there be a config setting for that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it safer to have a RepoUrl setting rather than have none.

I think it is important that we will not support multiple remotes when using the GVFS protocol, and I think that's the only time we use RepoUrl (other than logging).

{
GitProcess.ConfigResult remoteResult = gitProcess.GetFromLocalConfig($"remote.{remotes[0]}.url");
if (!remoteResult.TryParseAsString(out originUrl, out error))
{
originUrl = null;
}
}
}

if (originUrl == null)
{
throw new InvalidRepoException(this.WorkingDirectoryRoot, "Could not get origin url. remote 'origin' is not configured for this repo.'");
}

this.RepoUrl = originUrl.Trim();
this.RepoUrl = originUrl?.Trim() ?? string.Empty;
}

this.Authentication = authentication ?? new GitAuthentication(gitProcess, this.RepoUrl, this.WorkingDirectoryRoot);
Expand Down
2 changes: 1 addition & 1 deletion Scalar.Common/InvalidRepoException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class InvalidRepoException : Exception
public string RepoPath { get; }

public InvalidRepoException(string repoPath, string message)
: base(message)
: base($"path: '{repoPath}', message: '{message}'")
{
this.RepoPath = repoPath;
}
Expand Down
16 changes: 2 additions & 14 deletions Scalar.Common/ScalarEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@ public partial class ScalarEnlistment : Enlistment
private string gitVersion;
private string scalarVersion;

// New enlistment
public ScalarEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, GitAuthentication authentication)
: this(
enlistmentRoot,
Path.Combine(enlistmentRoot, ScalarConstants.WorkingDirectoryRootName),
repoUrl,
gitBinPath,
authentication)
{
}

// Existing, configured enlistment
private ScalarEnlistment(string enlistmentRoot, string workingDirectory, string repoUrl, string gitBinPath, GitAuthentication authentication)
public ScalarEnlistment(string enlistmentRoot, string workingDirectory, string repoUrl, string gitBinPath, GitAuthentication authentication)
: base(
enlistmentRoot,
workingDirectory,
Expand Down Expand Up @@ -74,7 +62,7 @@ public static ScalarEnlistment CreateFromDirectory(

if (createWithoutRepoURL)
{
return new ScalarEnlistment(enlistmentRoot, string.Empty, gitBinRoot, authentication);
return new ScalarEnlistment(enlistmentRoot, workingDirectory, string.Empty, gitBinRoot, authentication);
}

return new ScalarEnlistment(enlistmentRoot, workingDirectory, null, gitBinRoot, authentication);
Expand Down
2 changes: 1 addition & 1 deletion Scalar.UnitTests/Common/ScalarEnlistmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private class TestScalarEnlistment : ScalarEnlistment
private MockGitProcess gitProcess;

public TestScalarEnlistment()
: base("mock:\\path", "mock://repoUrl", "mock:\\git", authentication: null)
: base("mock:\\path", "mock:\\path", "mock://repoUrl", "mock:\\git", authentication: null)
{
this.gitProcess = new MockGitProcess();
this.gitProcess.SetExpectedCommandResult(
Expand Down
4 changes: 2 additions & 2 deletions Scalar.UnitTests/Mock/Common/MockScalarEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class MockScalarEnlistment : ScalarEnlistment
private MockGitProcess gitProcess;

public MockScalarEnlistment()
: base(Path.Combine("mock:", "path"), "mock://repoUrl", Path.Combine("mock:", "git"), authentication: null)
: base(Path.Combine("mock:", "path"), Path.Combine("mock:", "path"), "mock://repoUrl", Path.Combine("mock:", "git"), authentication: null)
{
this.GitObjectsRoot = Path.Combine("mock:", "path", ".git", "objects");
this.LocalObjectsRoot = this.GitObjectsRoot;
this.GitPackRoot = Path.Combine("mock:", "path", ".git", "objects", "pack");
}

public MockScalarEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, MockGitProcess gitProcess)
: base(enlistmentRoot, repoUrl, gitBinPath, authentication: null)
: base(enlistmentRoot, enlistmentRoot, repoUrl, gitBinPath, authentication: null)
{
this.gitProcess = gitProcess;
}
Expand Down
1 change: 1 addition & 0 deletions Scalar/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ private Result TryCreateEnlistment(
{
enlistment = new ScalarEnlistment(
normalizedEnlistementRootPath,
Path.Combine(normalizedEnlistementRootPath, ScalarConstants.WorkingDirectoryRootName),
this.RepositoryURL,
gitBinPath,
authentication: null);
Expand Down
5 changes: 3 additions & 2 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ tasks are:
commits. After writing a new file, verify the file was computed successfully.
This drastically improves the performance of commands like `git log --graph`.

* `fetch`: Fetch the latest data from the remote server. If using the GVFS
* `fetch`: Fetch the latest data from the remote servers. If using the GVFS
protocol, download the latest set of commit and tree packs from
the cache server or the origin remote. This will not update your local
the cache server or the origin remote. Otherwise, this step will fetch
the latest objects from each remote. This will not update your local
refs, so your `git fetch` commands will report all ref updates. Those
`git fetch` commands will be much faster as they will require much less
data transfer.
Expand Down