Skip to content

Commit 917f653

Browse files
committed
Remove the last uses of explicit config paths for Repository
These tests use the option to set a global configuration file with the filemode we want. But the filemode setting should be set per-repository as it comes down to the workdir for each repository. Switch to setting the configuration in the local configuration, which is also more in line with how it would exist in the wild.
1 parent f67f385 commit 917f653

File tree

2 files changed

+12
-50
lines changed

2 files changed

+12
-50
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10441044
repo.Config.Unset("core.filemode");
10451045
}
10461046

1047-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
1048-
1049-
var options = BuildFakeSystemConfigFilemodeOption(scd, true);
1050-
1051-
using (var repo = new Repository(path, options))
1047+
using (var repo = new Repository(path))
10521048
{
1049+
SetFilemode(repo, true);
10531050
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
10541051

10551052
Assert.Equal(1, changes.Count());
@@ -1059,34 +1056,18 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10591056
Assert.Equal(Mode.NonExecutableFile, change.Mode);
10601057
}
10611058

1062-
options = BuildFakeSystemConfigFilemodeOption(scd, false);
1063-
1064-
using (var repo = new Repository(path, options))
1059+
using (var repo = new Repository(path))
10651060
{
1061+
SetFilemode(repo, false);
10661062
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
10671063

10681064
Assert.Equal(0, changes.Count());
10691065
}
10701066
}
10711067

1072-
private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
1073-
SelfCleaningDirectory scd,
1074-
bool value)
1068+
void SetFilemode(Repository repo, bool value)
10751069
{
1076-
Directory.CreateDirectory(scd.DirectoryPath);
1077-
1078-
var options = new RepositoryOptions
1079-
{
1080-
SystemConfigurationLocation = Path.Combine(
1081-
scd.RootedDirectoryPath, "fake-system.config")
1082-
};
1083-
1084-
StringBuilder sb = new StringBuilder()
1085-
.AppendFormat("[core]{0}", Environment.NewLine)
1086-
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
1087-
Touch("", options.SystemConfigurationLocation, sb.ToString());
1088-
1089-
return options;
1070+
repo.Config.Set("core.filemode", value);
10901071
}
10911072

10921073
[Fact]

LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
127127
repo.Config.Unset("core.filemode", ConfigurationLevel.Local);
128128
}
129129

130-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
131-
132-
var options = BuildFakeSystemConfigFilemodeOption(scd, true);
133-
134-
using (var repo = new Repository(path, options))
130+
using (var repo = new Repository(path))
135131
{
132+
SetFilemode(repo, true);
136133
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
137134

138135
Assert.Equal(1, changes.Count());
@@ -142,34 +139,18 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
142139
Assert.Equal(Mode.NonExecutableFile, change.Mode);
143140
}
144141

145-
options = BuildFakeSystemConfigFilemodeOption(scd, false);
146-
147-
using (var repo = new Repository(path, options))
142+
using (var repo = new Repository(path))
148143
{
144+
SetFilemode(repo, false);
149145
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
150146

151147
Assert.Equal(0, changes.Count());
152148
}
153149
}
154150

155-
private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
156-
SelfCleaningDirectory scd,
157-
bool value)
151+
void SetFilemode(Repository repo, bool value)
158152
{
159-
Directory.CreateDirectory(scd.DirectoryPath);
160-
161-
var options = new RepositoryOptions
162-
{
163-
SystemConfigurationLocation = Path.Combine(
164-
scd.RootedDirectoryPath, "fake-system.config")
165-
};
166-
167-
StringBuilder sb = new StringBuilder()
168-
.AppendFormat("[core]{0}", Environment.NewLine)
169-
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
170-
File.WriteAllText(options.SystemConfigurationLocation, sb.ToString());
171-
172-
return options;
153+
repo.Config.Set("core.filemode", value);
173154
}
174155

175156
[Fact]

0 commit comments

Comments
 (0)