зеркало из https://github.com/github/libgit2sharp.git
Make RetrieveStatus() reload on-disk index beforehand
Fix #322 and #522
This commit is contained in:
Родитель
467fbd0ae6
Коммит
8effe572bc
|
@ -244,5 +244,39 @@ namespace LibGit2Sharp.Tests
|
|||
Assert.Throws<LockedFileException>(() => repo.Index.Stage("newfile"));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCopeWithExternalChangesToTheIndex()
|
||||
{
|
||||
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
|
||||
|
||||
Touch(scd.DirectoryPath, "a.txt", "a\n");
|
||||
Touch(scd.DirectoryPath, "b.txt", "b\n");
|
||||
|
||||
string path = Repository.Init(scd.DirectoryPath);
|
||||
|
||||
using (var repoWrite = new Repository(path))
|
||||
using (var repoRead = new Repository(path))
|
||||
{
|
||||
var writeStatus = repoWrite.Index.RetrieveStatus();
|
||||
Assert.True(writeStatus.IsDirty);
|
||||
Assert.Equal(0, repoWrite.Index.Count);
|
||||
|
||||
var readStatus = repoRead.Index.RetrieveStatus();
|
||||
Assert.True(readStatus.IsDirty);
|
||||
Assert.Equal(0, repoRead.Index.Count);
|
||||
|
||||
repoWrite.Index.Stage("*");
|
||||
repoWrite.Commit("message", Constants.Signature, Constants.Signature);
|
||||
|
||||
writeStatus = repoWrite.Index.RetrieveStatus();
|
||||
Assert.False(writeStatus.IsDirty);
|
||||
Assert.Equal(2, repoWrite.Index.Count);
|
||||
|
||||
readStatus = repoRead.Index.RetrieveStatus();
|
||||
Assert.False(readStatus.IsDirty);
|
||||
Assert.Equal(2, repoRead.Index.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,6 +492,9 @@ namespace LibGit2Sharp.Core
|
|||
out IndexSafeHandle index,
|
||||
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath indexpath);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
internal static extern int git_index_read(IndexSafeHandle index);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
internal static extern int git_index_remove_bypath(
|
||||
IndexSafeHandle index,
|
||||
|
|
|
@ -776,6 +776,15 @@ namespace LibGit2Sharp.Core
|
|||
}
|
||||
}
|
||||
|
||||
public static void git_index_read(IndexSafeHandle index)
|
||||
{
|
||||
using (ThreadAffinity())
|
||||
{
|
||||
int res = NativeMethods.git_index_read(index);
|
||||
Ensure.ZeroResult(res);
|
||||
}
|
||||
}
|
||||
|
||||
public static void git_index_remove_bypath(IndexSafeHandle index, FilePath path)
|
||||
{
|
||||
using (ThreadAffinity())
|
||||
|
|
|
@ -505,6 +505,7 @@ namespace LibGit2Sharp
|
|||
/// <returns>A <see cref="RepositoryStatus"/> holding the state of all the files.</returns>
|
||||
public virtual RepositoryStatus RetrieveStatus()
|
||||
{
|
||||
ReloadFromDisk();
|
||||
return new RepositoryStatus(repo);
|
||||
}
|
||||
|
||||
|
@ -559,6 +560,11 @@ namespace LibGit2Sharp
|
|||
Marshal.FreeHGlobal(indexEntry.Path);
|
||||
}
|
||||
|
||||
internal void ReloadFromDisk()
|
||||
{
|
||||
Proxy.git_index_read(handle);
|
||||
}
|
||||
|
||||
private string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
|
|
Загрузка…
Ссылка в новой задаче