¿Cómo cambiar / eliminar / agregar files usando libgit2sharp?

Tengo dos dates, desde y hasta. Tengo que encontrar los files cambiados en el repository entre esa diferencia de date y hacer una list de ella. Aquí hay una pregunta relacionada que obtiene la diferencia entre los treees. Obtenga files modificados / agregados / eliminados de una confirmación en LibGit2Sharp .

Entonces supongamos que intentas replicar:

git log --reverse --since "11/10/2015" --until="11/15/2015" --format="%cD %s" 

Una vez que tenga una list de confirmaciones, ICommitLog , a través de todos los ICommitLog del repos, una list de sucursales filtrada, etc., puede filtrar a través de Linq.

Entonces crea tu list de compromisos:

 var repo = new Repository ("/Users/sushi/code/playscript/mono"); var filter = new CommitFilter { SortBy = CommitSortStrategies.Time | CommitSortStrategies.Reverse, }; var commits = repo.Commits.QueryBy(filter); 

Ahora con el object ICommitLog commits , aplique un filter Linq en los objects de confirmación. En este caso, estoy usando la date del committer y filtrando los commits de 2 a 7 días a partir de hoy, pero recuerde que también hay una date de Author :

 var since = new DateTimeOffset(DateTime.Now.AddDays(-7)); var until = new DateTimeOffset(DateTime.Now.AddDays(-2)); var filtenetworkingCommitLog = commitLog.Where(c => c.Committer.When > since && c.Committer.When < until); foreach (Commit commit in filtenetworkingCommitLog) { Console.WriteLine("{0} : {1}", commit.Committer.When.ToLocalTime(), commit.MessageShort); } 

Resultados:

 11/15/2015 5:32:36 AM -08:00 : [runtime] Fix Thread.CurrentThread in non-root appdomains by setting the tls slot in start_wrapper, otherwise Thread.CurrentThread would create a new Thread object so there would be two. Fixes #35828. 11/15/2015 12:00:30 AM -08:00 : Fix a warning. .... 11/10/2015 6:41:09 AM -08:00 : Merge pull request #2214 from kumpera/fix_enum_get_get_hashcode 11/10/2015 6:07:50 AM -08:00 : [Mono.Posix] Update incorrect test 

Actualizar:

Me perdí una parte de esta respuesta, la list de files modificada …: – / (Necesito más café)

 git log --name-status --reverse --since "11/10/2015" --until="11/15/2015" --format="%cD %s" 

Se convierte en:

  var since = new DateTimeOffset(DateTime.Now.AddDays(-7)); var until = new DateTimeOffset(DateTime.Now.AddDays(-2)); var filtenetworkingCommitLog = commitLog.Where(c => c.Committer.When > since && c.Committer.When < until); foreach (Commit commit in filtenetworkingCommitLog) { Console.WriteLine("{0} : {1}", commit.Committer.When.ToLocalTime(), commit.MessageShort); foreach (var parent in commit.Parents) { foreach (TreeEntryChanges change in repo.Diff.Compare<TreeChanges>(parent.Tree, commit.Tree)) { Console.WriteLine ("\t{0} :\t{1}", change.Status, change.OldPath); } } } 

Ejemplo de salida:

 11/11/2015 8:09:41 AM -08:00 : Crashing test in mono_class_init() from a MonoGenericClass. Modified : mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs 11/11/2015 8:12:03 AM -08:00 : [runtime] mono_class_init() - don't look for metadata if the dynamic image doesn't have it. Modified : mono/metadata/class.c 11/11/2015 9:05:07 AM -08:00 : Merge pull request #2217 from rcruzs00/master Modified : mcs/tools/macpack/LOADER 11/11/2015 11:26:25 AM -08:00 : Merge pull request #2198 from BrzVlad/feature-concurrent-work Modified : mono/sgen/sgen-conf.h Modified : mono/sgen/sgen-gc.c Modified : mono/sgen/sgen-memory-governor.c Modified : mono/sgen/sgen-workers.c Modified : mono/sgen/sgen-workers.h Modified : acceptance-tests/.gitignore Added : acceptance-tests/GCStressTests/AssemblyExtensions.cs Added : acceptance-tests/GCStressTests/AssemblyLoadContext.cs Modified : acceptance-tests/Makefile.am Modified : acceptance-tests/SUBMODULES.json Modified : acceptance-tests/versions.mk 

Para omitir el logging y get solo la list de files dentro de la list de confirmaciones filtrada:

  git log --name-status --since "11/10/2015" --until="11/15/2015" --format="" 

Se convierte en:

 foreach (TreeEntryChanges change in repo.Diff.Compare<TreeChanges>(filtenetworkingCommitLog.First().Tree, filtenetworkingCommitLog.Last().Tree)) { Console.WriteLine ("\t{0}\t:\t{1}", change.Status, change.OldPath); } 

Ejemplo de salida:

 Modified : acceptance-tests/Makefile.am Modified : acceptance-tests/SUBMODULES.json Modified : external/referencesource Modified : mcs/class/Facades/Makefile Modified : mcs/class/Mono.Cairo/Mono.Cairo/Context.cs Modified : mcs/class/Mono.Security/Mono.Security.Interface/CertificateValidationHelper.cs Modified : mcs/class/Mono.Security/Mono.Security.Interface/MonoTlsProvider.cs Modified : mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/ActionBlockTest.cs Modified : mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/BatchBlockTest.cs Modified : mcs/class/System.Threading.Tasks.Data 

Tomé un enfoque diferente para resolver esto más tarde.

 using(var repo = new Repository("c:\\_Temp\\Repo")) { List<string> shalist = new List<string>(); foreach(Commit c in repo.Commits) { DateTime since = DateTime.Parse("10/29/2015 12:00:00 AM"); DateTime untill= c.Author.When.Date; if(untill >= since) { shalist.Add(c.sha.Tostring()); } } Tree cmTree1 = repo.Lookup<Commit>(shalist.First()).Tree; Tree cmTree2 = repo.Lookup<Commit>(shalist.Last()).Tree; var patch = repo.Diff.Compare<patch>(cmTree1, cmTree2); foreach(var ptc in patch) { Console.WriteLine(ptc.Path); } } 

Esto mostrará todos los files modificados en el range de dates since - untill