enhance: skip auto fetching when index.lock file exists in the repository's git dir

This commit is contained in:
leo 2024-09-18 14:49:53 +08:00
parent ba9c3058ed
commit 9c6745c271
No known key found for this signature in database
2 changed files with 10 additions and 4 deletions

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -20,6 +21,7 @@ namespace SourceGit.Models
public class Job public class Job
{ {
public string IndexLockFile = string.Empty;
public Commands.Fetch Cmd = null; public Commands.Fetch Cmd = null;
public DateTime NextRunTimepoint = DateTime.MinValue; public DateTime NextRunTimepoint = DateTime.MinValue;
} }
@ -75,8 +77,11 @@ namespace SourceGit.Models
foreach (var job in uptodate) foreach (var job in uptodate)
{ {
job.Cmd.Exec(); if (!File.Exists(job.IndexLockFile))
job.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)); {
job.Cmd.Exec();
job.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval));
}
} }
Thread.Sleep(2000); Thread.Sleep(2000);
@ -86,10 +91,11 @@ namespace SourceGit.Models
}); });
} }
public void AddRepository(string repo) public void AddRepository(string repo, string gitDir)
{ {
var job = new Job var job = new Job
{ {
IndexLockFile = Path.Combine(gitDir, "index.lock"),
Cmd = new Commands.Fetch(repo, "--all", true, false, null) { RaiseError = false }, Cmd = new Commands.Fetch(repo, "--all", true, false, null) { RaiseError = false },
NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)), NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)),
}; };

View file

@ -271,7 +271,7 @@ namespace SourceGit.ViewModels
repo.Open(); repo.Open();
ActiveWorkspace.AddRepository(repo.FullPath); ActiveWorkspace.AddRepository(repo.FullPath);
Models.AutoFetchManager.Instance.AddRepository(repo.FullPath); Models.AutoFetchManager.Instance.AddRepository(repo.FullPath, repo.GitDir);
if (page == null) if (page == null)
{ {