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

Add sparse checkout support #772

Merged
merged 1 commit into from
Dec 31, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 52 additions & 1 deletion src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@ public void OpenRepository_WorkingDirectorySpecifiedInConfig()
Assert.Equal(workingDir2.Path, repository.WorkingDirectory);
}

[Fact]
public void OpenRepository_SparseV2()
{
using var temp = new TempRoot();

var workingDir = temp.CreateDirectory();
var gitDir = workingDir.CreateDirectory(".git");

gitDir.CreateFile("HEAD");
gitDir.CreateFile("config").WriteAllText(@"
[core]
repositoryformatversion = 1
[extensions]
worktreeConfig = true");

Assert.True(GitRepository.TryFindRepository(gitDir.Path, out var location));
Assert.Equal(gitDir.Path, location.CommonDirectory);
Assert.Equal(gitDir.Path, location.GitDirectory);
Assert.Null(location.WorkingDirectory);

var repository = GitRepository.OpenRepository(location, GitEnvironment.Empty);
Assert.Equal(gitDir.Path, repository.CommonDirectory);
Assert.Equal(gitDir.Path, repository.GitDirectory);
Assert.Null(repository.WorkingDirectory);
}

[Fact]
public void OpenRepository_VersionNotSupported()
{
Expand All @@ -223,7 +249,32 @@ public void OpenRepository_VersionNotSupported()
gitDir.CreateDirectory("refs").CreateDirectory("heads").CreateFile("master").WriteAllText("0000000000000000000000000000000000000000");
gitDir.CreateDirectory("objects");

gitDir.CreateFile("config").WriteAllText("[core]repositoryformatversion = 1");
gitDir.CreateFile("config").WriteAllText("[core]repositoryformatversion = 2");

var src = workingDir.CreateDirectory("src");

Assert.Throws<NotSupportedException>(() => GitRepository.OpenRepository(src.Path, new GitEnvironment(homeDir.Path)));
}

[Fact]
public void OpenRepository_V2ExtensionNotSupported()
{
using var temp = new TempRoot();

var homeDir = temp.CreateDirectory();

var workingDir = temp.CreateDirectory();
var gitDir = workingDir.CreateDirectory(".git");

gitDir.CreateFile("HEAD").WriteAllText("ref: refs/heads/master");
gitDir.CreateDirectory("refs").CreateDirectory("heads").CreateFile("master").WriteAllText("0000000000000000000000000000000000000000");
gitDir.CreateDirectory("objects");

gitDir.CreateFile("config").WriteAllText(@"
[core]
repositoryformatversion = 1
[extensions]
newExtension = true");

var src = workingDir.CreateDirectory("src");

Expand Down
20 changes: 19 additions & 1 deletion src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Build.Tasks.Git
{
internal sealed class GitRepository
{
private const int SupportedGitRepoFormatVersion = 0;
private const int SupportedGitRepoFormatVersion = 1;

private const string CommonDirFileName = "commondir";
private const string GitDirName = ".git";
Expand All @@ -23,6 +23,8 @@ internal sealed class GitRepository
internal const string GitHeadFileName = "HEAD";

private const string GitModulesFileName = ".gitmodules";
private static readonly string[] KnownExtensions = new[] { "noop", "preciousObjects", "partialclone", "worktreeConfig" };


public GitConfig Config { get; }

Expand Down Expand Up @@ -124,6 +126,22 @@ public static GitRepository OpenRepository(GitRepositoryLocation location, GitEn
throw new NotSupportedException(string.Format(Resources.UnsupportedRepositoryVersion, versionStr, SupportedGitRepoFormatVersion));
}

if (version == 1)
{
// When reading the core.repositoryformatversion variable, a git implementation which supports version 1 MUST
// also read any configuration keys found in the extensions section of the configuration file.
//
// If a version-1 repository specifies any extensions.* keys that the running git has not implemented, the operation MUST NOT proceed.
// Similarly, if the value of any known key is not understood by the implementation,the operation MUST NOT proceed.
foreach (var variable in config.Variables)
{
if (variable.Key.SectionNameEquals("extensions") && !KnownExtensions.Contains(variable.Key.VariableName, StringComparer.OrdinalIgnoreCase))
{
throw new NotSupportedException(string.Format(Resources.UnsupportedRepositoryExtension, variable.Key.VariableName, string.Join(", ", KnownExtensions)));
}
}
}

return new GitRepository(environment, config, location.GitDirectory, location.CommonDirectory, workingDirectory);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Build.Tasks.Git/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<data name="UnsupportedRepositoryVersion" xml:space="preserve">
<value>Unsupported repository version {0}. Only versions up to {1} are supported.</value>
</data>
<data name="UnsupportedRepositoryExtension" xml:space="preserve">
<value>Unsupported repository extension {0}. Only {1} are supported.</value>
</data>
<data name="PathSpecifiedInFileIsNotAbsolute" xml:space="preserve">
<value>Path specified in file '{0}' is not absolute: '{1}'.</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Nejde najít úložiště s pracovním adresářem, který obsahuje adresář {0}.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">Nepodporovaná verze úložiště: {0}. Podporují se jenom verze do {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Das Repository mit dem Arbeitsverzeichnis, welches das Verzeichnis "{0}" enthält, wurde nicht gefunden.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">Nicht unterstützte Repositoryversion {0}. Nur Versionen bis {1} werden unterstützt.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">No se puede encontrar el repositorio con el directorio de trabajo que contiene el directorio "{0}".</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">Versión de repositorio {0} no admitida. Solo se admiten las versiones hasta {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Impossible de localiser le dépôt avec le répertoire de travail contenant le répertoire '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">La version du dépôt {0} n'est pas prise en charge. Seules les versions jusqu'à {1} sont prises en charge.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Non è possibile individuare il repository con la directory di lavoro che contiene la directory '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">La versione {0} del repository non è supportata. Sono supportate solo le versioni fino alla {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">ディレクトリ '{0}' を含む作業ディレクトリがあるリポジトリが見つかりません。</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">サポートされていないリポジトリ バージョン {0}。{1} までのバージョンのみがサポートされています。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">디렉터리 '{0}'이(가) 포함된 작업 디렉터리로 리포지토리를 찾을 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">{0}은(는) 지원되지 않는 리포지토리 버전입니다. 버전은 최대 {1}까지만 지원됩니다.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Nie można zlokalizować repozytorium z katalogiem roboczym zawierającym katalog „{0}”.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">Nieobsługiwana wersja repozytorium {0}. Obsługiwane są tylko wersje do {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Não é possível localizar o repositório com o diretório de trabalho que contém o diretório '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">{0} de versão do repositório sem suporte. Há suporte apenas para versões de até {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">Не удается найти репозиторий с рабочим каталогом, содержащим каталог "{0}".</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">Неподдерживаемая версия репозитория {0}. Поддерживаются только версии до {1}.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">'{0}' dizinini içeren çalışma dizini içeren depo bulunamıyor.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">{0} depo sürümü desteklenmiyor. Yalnızca {1} sürümüne kadar olan sürümler desteklenir.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">找不到具有带目录“{0}”的工作目录的存储库。</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">不支持存储库版本 {0}。支持的最高版本为 {1}。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<target state="translated">找不到具有包含目錄 '{0}' 之工作目錄的存放庫。</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryExtension">
<source>Unsupported repository extension {0}. Only {1} are supported.</source>
<target state="new">Unsupported repository extension {0}. Only {1} are supported.</target>
<note />
</trans-unit>
<trans-unit id="UnsupportedRepositoryVersion">
<source>Unsupported repository version {0}. Only versions up to {1} are supported.</source>
<target state="translated">不支援的存放庫版本 {0}。最大只支援版本 {1}。</target>
Expand Down