feature<Repository>: add settings for fetching remotes automatically

This commit is contained in:
leo 2021-04-08 10:57:28 +08:00
parent 1c24699f70
commit 245084fd34
6 changed files with 75 additions and 57 deletions

View file

@ -118,6 +118,10 @@ namespace SourceGit {
/// </summary>
public int LastCheckUpdate { get; set; } = 0;
/// <summary>
/// Fetch remotes automatically?
/// </summary>
public bool AutoFetchRemotes { get; set; } = true;
/// <summary>
/// Settings for executables.
/// </summary>
public ToolSetting Tools { get; set; } = new ToolSetting();

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Threading;
namespace SourceGit.Git {
@ -65,12 +66,13 @@ namespace SourceGit.Git {
private List<Tag> cachedTags = new List<Tag>();
private FileSystemWatcher gitDirWatcher = null;
private FileSystemWatcher workingCopyWatcher = null;
private DispatcherTimer timer = null;
private Timer timer = null;
private bool isWatcherDisabled = false;
private long nextUpdateTags = 0;
private long nextUpdateLocalChanges = 0;
private long nextUpdateStashes = 0;
private long nextUpdateTree = 0;
private long nextFetchingRemotes = 0;
private string featurePrefix = null;
private string releasePrefix = null;
@ -197,6 +199,9 @@ namespace SourceGit.Git {
OnWorkingCopyChanged?.Invoke();
OnTagChanged?.Invoke();
nextUpdateLocalChanges = 0;
nextUpdateTags = 0;
nextUpdateTree = 0;
isWatcherDisabled = false;
}
#endregion
@ -250,6 +255,7 @@ namespace SourceGit.Git {
/// </summary>
public void Open() {
isWatcherDisabled = false;
nextFetchingRemotes = DateTime.Now.AddMinutes(10).ToFileTime();
GitDir = ".git";
RunCommand("rev-parse --git-dir", line => {
@ -287,10 +293,7 @@ namespace SourceGit.Git {
workingCopyWatcher.Deleted += OnWorkingCopyFSChanged;
workingCopyWatcher.EnableRaisingEvents = true;
timer = new DispatcherTimer();
timer.Tick += Tick;
timer.Interval = TimeSpan.FromSeconds(.1);
timer.Start();
timer = new Timer(Tick, null, 100, 100);
featurePrefix = GetConfig("gitflow.prefix.feature");
releasePrefix = GetConfig("gitflow.prefix.release");
@ -320,7 +323,7 @@ namespace SourceGit.Git {
workingCopyWatcher.EnableRaisingEvents = false;
gitDirWatcher.Dispose();
workingCopyWatcher.Dispose();
timer.Stop();
timer.Dispose();
gitDirWatcher = null;
workingCopyWatcher = null;
@ -338,7 +341,13 @@ namespace SourceGit.Git {
isWatcherDisabled = !enabled;
}
private void Tick(object sender, EventArgs e) {
private void Tick(object sender) {
var now = DateTime.Now.ToFileTime();
if (now >= nextFetchingRemotes) {
Fetch(null, true, null, false);
return;
}
if (isWatcherDisabled) {
nextUpdateLocalChanges = 0;
nextUpdateStashes = 0;
@ -347,7 +356,6 @@ namespace SourceGit.Git {
return;
}
var now = DateTime.Now.ToFileTime();
if (nextUpdateLocalChanges > 0 && now >= nextUpdateLocalChanges) {
nextUpdateLocalChanges = 0;
OnWorkingCopyChanged?.Invoke();
@ -443,8 +451,10 @@ namespace SourceGit.Git {
/// <param name="remote"></param>
/// <param name="prune"></param>
/// <param name="onProgress"></param>
public void Fetch(Remote remote, bool prune, Action<string> onProgress) {
/// <param name="raiseError"></param>
public void Fetch(Remote remote, bool prune, Action<string> onProgress, bool raiseError = true) {
isWatcherDisabled = true;
nextFetchingRemotes = DateTime.Now.AddMinutes(10).ToFileTime();
var args = "-c credential.helper=manager fetch --progress --verbose ";
@ -461,6 +471,9 @@ namespace SourceGit.Git {
}, true);
OnSubmoduleChanged?.Invoke();
if (!raiseError) errs = null;
nextFetchingRemotes = DateTime.Now.AddMinutes(10).ToFileTime();
AssertCommand(errs);
}
@ -475,6 +488,7 @@ namespace SourceGit.Git {
/// <param name="onProgress">Progress message handler.</param>
public void Pull(string remote, string branch, Action<string> onProgress, bool rebase = false, bool autostash = false) {
isWatcherDisabled = true;
nextFetchingRemotes = DateTime.Now.AddMinutes(10).ToFileTime();
var args = "-c credential.helper=manager pull --verbose --progress ";
var needPopStash = false;

View file

@ -87,8 +87,6 @@
<sys:String x:Key="Text.Configure.User.Placeholder">User name for this repository</sys:String>
<sys:String x:Key="Text.Configure.Email">Email :</sys:String>
<sys:String x:Key="Text.Configure.Email.Placeholder">Email address</sys:String>
<sys:String x:Key="Text.Configure.CommitTemplate">COMMIT TEMPLATE</sys:String>
<sys:String x:Key="Text.Configure.Template">Template :</sys:String>
<sys:String x:Key="Text.CreateBranch">Create Branch</sys:String>
<sys:String x:Key="Text.CreateBranch.Title">Create Local Branch</sys:String>
@ -345,10 +343,11 @@
<sys:String x:Key="Text.Preference">Preference</sys:String>
<sys:String x:Key="Text.Preference.General">GENERAL SETTING</sys:String>
<sys:String x:Key="Text.Preference.RestartRequired">RESTART REQUIRED</sys:String>
<sys:String x:Key="Text.Preference.Locale">Display Language :</sys:String>
<sys:String x:Key="Text.Preference.UseLight">Light Theme :</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">Check for Update :</sys:String>
<sys:String x:Key="Text.Preference.Locale">Language :</sys:String>
<sys:String x:Key="Text.Preference.AvatarServer">Avatar Server :</sys:String>
<sys:String x:Key="Text.Preference.UseLight">Use light theme</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">Check for update</sys:String>
<sys:String x:Key="Text.Preference.AutoFetch">Fetch remotes automatically</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT INSTANCE</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">Install Path :</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>

View file

@ -87,8 +87,6 @@
<sys:String x:Key="Text.Configure.User.Placeholder">应用于本仓库的用户名</sys:String>
<sys:String x:Key="Text.Configure.Email">邮箱 </sys:String>
<sys:String x:Key="Text.Configure.Email.Placeholder">邮箱地址</sys:String>
<sys:String x:Key="Text.Configure.CommitTemplate">提交模板</sys:String>
<sys:String x:Key="Text.Configure.Template">模板内容 </sys:String>
<sys:String x:Key="Text.CreateBranch">新建分支</sys:String>
<sys:String x:Key="Text.CreateBranch.Title">创建本地分支</sys:String>
@ -346,9 +344,10 @@
<sys:String x:Key="Text.Preference.General">通用配置</sys:String>
<sys:String x:Key="Text.Preference.RestartRequired">需要重启软件</sys:String>
<sys:String x:Key="Text.Preference.Locale">显示语言 </sys:String>
<sys:String x:Key="Text.Preference.UseLight">启用浅色主题 </sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">检测更新 </sys:String>
<sys:String x:Key="Text.Preference.AvatarServer">头像服务 </sys:String>
<sys:String x:Key="Text.Preference.UseLight">启用浅色主题</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">启用检测更新</sys:String>
<sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT配置</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">安装路径 </sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String>

View file

@ -9,8 +9,8 @@
<Grid ClipToBounds="True">
<Border Background="Transparent" MouseLeftButtonDown="Close"/>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Width="Auto" Height="Auto" Background="{StaticResource Brush.Popup}">
<Border x:Name="popupContent" Padding="8" Width="Auto" Height="Auto" BorderThickness="1,0,1,1" BorderBrush="{StaticResource Brush.Border0}" SnapsToDevicePixels="True"/>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Width="Auto" Height="Auto">
<Border x:Name="popupContent" Padding="8" Width="Auto" Height="Auto" Background="{StaticResource Brush.Popup}" BorderThickness="1,0,1,1" BorderBrush="{StaticResource Brush.Border0}" SnapsToDevicePixels="True"/>
<Border x:Name="status" Visibility="Collapsed" Background="{StaticResource Brush.Popup}" Margin="1,0,1,1" Opacity=".9">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">

View file

@ -8,7 +8,7 @@
xmlns:app="clr-namespace:SourceGit"
xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d"
Height="588" Width="500"
Height="616" Width="500"
Title="{StaticResource Text.Preference}"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
@ -64,6 +64,7 @@
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="18"/>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
@ -81,7 +82,7 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="136"/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
@ -99,22 +100,8 @@
VerticalContentAlignment="Center"
DisplayMemberPath="Desc"
SelectionChanged="ChangeLanguage"/>
<Label Grid.Row="2" Grid.Column="0" Content="{StaticResource Text.Preference.UseLight}" HorizontalAlignment="Right"/>
<CheckBox
Grid.Row="2"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=UI.UseLightTheme, Mode=TwoWay}"
TextElement.FontStyle="Italic"/>
<Label Grid.Row="3" Grid.Column="0" Content="{StaticResource Text.Preference.CheckUpdate}" HorizontalAlignment="Right"/>
<CheckBox
Grid.Row="3"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=CheckUpdate, Mode=TwoWay}"
TextElement.FontStyle="Italic"/>
<Label Grid.Row="4" Grid.Column="0" Content="{StaticResource Text.Preference.AvatarServer}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="4" Grid.Column="1"
<Label Grid.Row="2" Grid.Column="0" Content="{StaticResource Text.Preference.AvatarServer}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="2" Grid.Column="1"
x:Name="cmbAvatarServer"
Height="24"
Width="140"
@ -122,11 +109,26 @@
VerticalContentAlignment="Center"
DisplayMemberPath="Desc"
SelectionChanged="ChangeAvatarServer"/>
<CheckBox
Grid.Row="3"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=UI.UseLightTheme, Mode=TwoWay}"
Content="{StaticResource Text.Preference.UseLight}"/>
<CheckBox
Grid.Row="4"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=CheckUpdate, Mode=TwoWay}"
Content="{StaticResource Text.Preference.CheckUpdate}"/>
<CheckBox
Grid.Row="5"
Grid.Column="1"
IsChecked="{Binding Source={x:Static app:App.Setting}, Path=AutoFetchRemotes, Mode=TwoWay}"
Content="{StaticResource Text.Preference.AutoFetch}"/>
<!-- GIT相关配置 -->
<Label Grid.Row="6" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Git}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="7" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="7" Grid.Column="1">
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Git}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="8" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="8" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -141,8 +143,8 @@
<Path Width="14" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<Label Grid.Row="8" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Dir}" HorizontalAlignment="Right"/>
<Grid Grid.Row="8" Grid.Column="1">
<Label Grid.Row="9" Grid.Column="0" Content="{StaticResource Text.Preference.Git.Dir}" HorizontalAlignment="Right"/>
<Grid Grid.Row="9" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -159,13 +161,13 @@
</Grid>
<!-- Global User -->
<Label Grid.Row="10" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Global}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="11" Grid.Column="0" Content="{StaticResource Text.Preference.User}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="11" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="12" Grid.Column="0" Content="{StaticResource Text.Preference.Email}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="12" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="13" Grid.Column="0" Content="{StaticResource Text.Preference.CRLF}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="13" Grid.Column="1"
<Label Grid.Row="11" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Global}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="12" Grid.Column="0" Content="{StaticResource Text.Preference.User}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="12" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
<Label Grid.Row="13" Grid.Column="0" Content="{StaticResource Text.Preference.Email}" HorizontalAlignment="Right"/>
<TextBox Grid.Row="13" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
<Label Grid.Row="14" Grid.Column="0" Content="{StaticResource Text.Preference.CRLF}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="14" Grid.Column="1"
x:Name="cmbAutoCRLF"
Height="24"
HorizontalAlignment="Stretch"
@ -182,9 +184,9 @@
</ComboBox>
<!-- 合并工具配置 -->
<Label Grid.Row="15" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Merger}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="16" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Type}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="16" Grid.Column="1"
<Label Grid.Row="16" Grid.ColumnSpan="2" Content="{StaticResource Text.Preference.Merger}" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
<Label Grid.Row="17" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Type}" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="17" Grid.Column="1"
Height="24"
Padding="2,0,0,0"
HorizontalContentAlignment="Left"
@ -193,8 +195,8 @@
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
DisplayMemberPath="Name"
SelectionChanged="ChangeMergeTool"/>
<Label Grid.Row="17" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="17" Grid.Column="1">
<Label Grid.Row="18" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Path}" HorizontalAlignment="Right"/>
<Grid Grid.Row="18" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="28"/>
@ -209,8 +211,8 @@
<Path Width="14" Data="{StaticResource Icon.Folder}"/>
</Button>
</Grid>
<Label Grid.Row="18" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Cmd}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="18" Grid.Column="1"
<Label Grid.Row="19" Grid.Column="0" Content="{StaticResource Text.Preference.Merger.Cmd}" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="19" Grid.Column="1"
x:Name="txtMergeParam"
VerticalAlignment="Center"
Foreground="{StaticResource Brush.FG2}"/>