mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
fix(Repository): separated git dir for submodules
This commit is contained in:
parent
39e55a3f2d
commit
646a80a395
5 changed files with 93 additions and 77 deletions
|
@ -28,22 +28,6 @@ namespace SourceGit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Interactive rebase sequence file.
|
|
||||||
/// </summary>
|
|
||||||
public static string InteractiveRebaseScript {
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// TODO file for interactive rebase.
|
|
||||||
/// </summary>
|
|
||||||
public static string InteractiveRebaseTodo {
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error handler.
|
/// Error handler.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -66,6 +50,22 @@ namespace SourceGit {
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void OnAppStartup(object sender, StartupEventArgs e) {
|
private void OnAppStartup(object sender, StartupEventArgs e) {
|
||||||
|
// Use this app as a sequence editor?
|
||||||
|
var args = e.Args;
|
||||||
|
if (args.Length > 1) {
|
||||||
|
if (args[0] == "--interactive-rebase") {
|
||||||
|
if (args.Length < 3) {
|
||||||
|
Environment.Exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(args[2], File.ReadAllText(args[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment.Exit(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Try auto configure git via registry.
|
// Try auto configure git via registry.
|
||||||
if (!IsGitConfigured) {
|
if (!IsGitConfigured) {
|
||||||
var root = RegistryKey.OpenBaseKey(
|
var root = RegistryKey.OpenBaseKey(
|
||||||
|
@ -81,23 +81,6 @@ namespace SourceGit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Files for interactive rebase.
|
|
||||||
InteractiveRebaseScript = Path.Combine(
|
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
||||||
"SourceGit",
|
|
||||||
"rebase.bat");
|
|
||||||
InteractiveRebaseTodo = Path.Combine(
|
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
||||||
"SourceGit",
|
|
||||||
"REBASE_TODO");
|
|
||||||
if (!File.Exists(InteractiveRebaseScript)) {
|
|
||||||
var folder = Path.GetDirectoryName(InteractiveRebaseScript);
|
|
||||||
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
|
||||||
|
|
||||||
File.WriteAllText(InteractiveRebaseScript, $"@echo off\ntype \"{InteractiveRebaseTodo}\" > .git\\rebase-merge\\git-rebase-todo");
|
|
||||||
File.WriteAllText(InteractiveRebaseTodo, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply themes
|
// Apply themes
|
||||||
if (Preference.UIUseLightTheme) {
|
if (Preference.UIUseLightTheme) {
|
||||||
foreach (var rs in Current.Resources.MergedDictionaries) {
|
foreach (var rs in Current.Resources.MergedDictionaries) {
|
||||||
|
|
|
@ -59,11 +59,13 @@ namespace SourceGit.Git {
|
||||||
|
|
||||||
#region PROPERTIES_RUNTIME
|
#region PROPERTIES_RUNTIME
|
||||||
[XmlIgnore] public Repository Parent = null;
|
[XmlIgnore] public Repository Parent = null;
|
||||||
|
[XmlIgnore] public string GitDir = null;
|
||||||
|
|
||||||
private List<Remote> cachedRemotes = new List<Remote>();
|
private List<Remote> cachedRemotes = new List<Remote>();
|
||||||
private List<Branch> cachedBranches = new List<Branch>();
|
private List<Branch> cachedBranches = new List<Branch>();
|
||||||
private List<Tag> cachedTags = new List<Tag>();
|
private List<Tag> cachedTags = new List<Tag>();
|
||||||
private FileSystemWatcher watcher = null;
|
private FileSystemWatcher gitDirWatcher = null;
|
||||||
|
private FileSystemWatcher workingCopyWatcher = null;
|
||||||
private DispatcherTimer timer = null;
|
private DispatcherTimer timer = null;
|
||||||
private bool isWatcherDisabled = false;
|
private bool isWatcherDisabled = false;
|
||||||
private long nextUpdateTags = 0;
|
private long nextUpdateTags = 0;
|
||||||
|
@ -276,16 +278,41 @@ namespace SourceGit.Git {
|
||||||
LastOpenTime = DateTime.Now.ToFileTime();
|
LastOpenTime = DateTime.Now.ToFileTime();
|
||||||
isWatcherDisabled = false;
|
isWatcherDisabled = false;
|
||||||
|
|
||||||
watcher = new FileSystemWatcher();
|
GitDir = ".git";
|
||||||
watcher.Path = Path;
|
RunCommand("rev-parse --git-dir", line => {
|
||||||
watcher.Filter = "*";
|
GitDir = line;
|
||||||
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
});
|
||||||
watcher.IncludeSubdirectories = true;
|
if (!System.IO.Path.IsPathRooted(GitDir)) GitDir = System.IO.Path.Combine(Path, GitDir);
|
||||||
watcher.Created += OnFSChanged;
|
|
||||||
watcher.Renamed += OnFSChanged;
|
var checkGitDir = new DirectoryInfo(GitDir);
|
||||||
watcher.Changed += OnFSChanged;
|
if (!checkGitDir.Exists) {
|
||||||
watcher.Deleted += OnFSChanged;
|
App.RaiseError("GIT_DIR for this repository NOT FOUND!");
|
||||||
watcher.EnableRaisingEvents = true;
|
return;
|
||||||
|
} else {
|
||||||
|
GitDir = checkGitDir.FullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
gitDirWatcher = new FileSystemWatcher();
|
||||||
|
gitDirWatcher.Path = GitDir;
|
||||||
|
gitDirWatcher.Filter = "*";
|
||||||
|
gitDirWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
||||||
|
gitDirWatcher.IncludeSubdirectories = true;
|
||||||
|
gitDirWatcher.Created += OnGitDirFSChanged;
|
||||||
|
gitDirWatcher.Renamed += OnGitDirFSChanged;
|
||||||
|
gitDirWatcher.Changed += OnGitDirFSChanged;
|
||||||
|
gitDirWatcher.Deleted += OnGitDirFSChanged;
|
||||||
|
gitDirWatcher.EnableRaisingEvents = true;
|
||||||
|
|
||||||
|
workingCopyWatcher = new FileSystemWatcher();
|
||||||
|
workingCopyWatcher.Path = Path;
|
||||||
|
workingCopyWatcher.Filter = "*";
|
||||||
|
workingCopyWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName;
|
||||||
|
workingCopyWatcher.IncludeSubdirectories = true;
|
||||||
|
workingCopyWatcher.Created += OnWorkingCopyFSChanged;
|
||||||
|
workingCopyWatcher.Renamed += OnWorkingCopyFSChanged;
|
||||||
|
workingCopyWatcher.Changed += OnWorkingCopyFSChanged;
|
||||||
|
workingCopyWatcher.Deleted += OnWorkingCopyFSChanged;
|
||||||
|
workingCopyWatcher.EnableRaisingEvents = true;
|
||||||
|
|
||||||
timer = new DispatcherTimer();
|
timer = new DispatcherTimer();
|
||||||
timer.Tick += Tick;
|
timer.Tick += Tick;
|
||||||
|
@ -315,11 +342,14 @@ namespace SourceGit.Git {
|
||||||
cachedRemotes.Clear();
|
cachedRemotes.Clear();
|
||||||
cachedTags.Clear();
|
cachedTags.Clear();
|
||||||
|
|
||||||
watcher.EnableRaisingEvents = false;
|
gitDirWatcher.EnableRaisingEvents = false;
|
||||||
watcher.Dispose();
|
workingCopyWatcher.EnableRaisingEvents = false;
|
||||||
|
gitDirWatcher.Dispose();
|
||||||
|
workingCopyWatcher.Dispose();
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
watcher = null;
|
gitDirWatcher = null;
|
||||||
|
workingCopyWatcher = null;
|
||||||
timer = null;
|
timer = null;
|
||||||
featurePrefix = null;
|
featurePrefix = null;
|
||||||
releasePrefix = null;
|
releasePrefix = null;
|
||||||
|
@ -367,26 +397,26 @@ namespace SourceGit.Git {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFSChanged(object sender, FileSystemEventArgs e) {
|
private void OnGitDirFSChanged(object sender, FileSystemEventArgs e) {
|
||||||
if (string.IsNullOrEmpty(e.Name)) return;
|
if (string.IsNullOrEmpty(e.Name)) return;
|
||||||
|
if (e.Name.StartsWith("index")) return;
|
||||||
|
|
||||||
if (e.Name.StartsWith(".git", StringComparison.Ordinal)) {
|
if (e.Name.StartsWith("refs\\tags", StringComparison.Ordinal)) {
|
||||||
if (e.Name.Equals(".git") || e.Name.StartsWith(".git\\index")) return;
|
|
||||||
|
|
||||||
if (e.Name.Equals(".gitignore") || e.Name.Equals(".gitattributes")) {
|
|
||||||
nextUpdateLocalChanges = DateTime.Now.AddSeconds(1.5).ToFileTime();
|
|
||||||
} else if (e.Name.StartsWith(".git\\refs\\tags", StringComparison.Ordinal)) {
|
|
||||||
nextUpdateTags = DateTime.Now.AddSeconds(.5).ToFileTime();
|
nextUpdateTags = DateTime.Now.AddSeconds(.5).ToFileTime();
|
||||||
} else if (e.Name.StartsWith(".git\\refs\\stash", StringComparison.Ordinal)) {
|
} else if (e.Name.StartsWith("refs\\stash", StringComparison.Ordinal)) {
|
||||||
nextUpdateStashes = DateTime.Now.AddSeconds(.5).ToFileTime();
|
nextUpdateStashes = DateTime.Now.AddSeconds(.5).ToFileTime();
|
||||||
} else if (e.Name.EndsWith("_HEAD", StringComparison.Ordinal) ||
|
} else if (e.Name.EndsWith("_HEAD", StringComparison.Ordinal) ||
|
||||||
e.Name.StartsWith(".git\\refs\\heads", StringComparison.Ordinal) ||
|
e.Name.StartsWith("refs\\heads", StringComparison.Ordinal) ||
|
||||||
e.Name.StartsWith(".git\\refs\\remotes", StringComparison.Ordinal)) {
|
e.Name.StartsWith("refs\\remotes", StringComparison.Ordinal)) {
|
||||||
nextUpdateTree = DateTime.Now.AddSeconds(.5).ToFileTime();
|
nextUpdateTree = DateTime.Now.AddSeconds(.5).ToFileTime();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
nextUpdateLocalChanges = DateTime.Now.AddSeconds(1.5).ToFileTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnWorkingCopyFSChanged(object sender, FileSystemEventArgs e) {
|
||||||
|
if (string.IsNullOrEmpty(e.Name)) return;
|
||||||
|
if (e.Name == ".git" || e.Name.StartsWith(".git\\")) return;
|
||||||
|
|
||||||
|
nextUpdateLocalChanges = DateTime.Now.AddSeconds(1.5).ToFileTime();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -383,11 +383,10 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
#region MERGE_ABORTS
|
#region MERGE_ABORTS
|
||||||
public void DetectMergeState() {
|
public void DetectMergeState() {
|
||||||
var gitDir = Path.Combine(repo.Path, ".git");
|
var cherryPickMerge = Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD");
|
||||||
var cherryPickMerge = Path.Combine(gitDir, "CHERRY_PICK_HEAD");
|
var rebaseMerge = Path.Combine(repo.GitDir, "REBASE_HEAD");
|
||||||
var rebaseMerge = Path.Combine(gitDir, "REBASE_HEAD");
|
var revertMerge = Path.Combine(repo.GitDir, "REVERT_HEAD");
|
||||||
var revertMerge = Path.Combine(gitDir, "REVERT_HEAD");
|
var otherMerge = Path.Combine(repo.GitDir, "MERGE_HEAD");
|
||||||
var otherMerge = Path.Combine(gitDir, "MERGE_HEAD");
|
|
||||||
|
|
||||||
if (File.Exists(cherryPickMerge)) {
|
if (File.Exists(cherryPickMerge)) {
|
||||||
abortCommand = "cherry-pick";
|
abortCommand = "cherry-pick";
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
@ -255,7 +257,8 @@ namespace SourceGit.UI {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start(object sender, RoutedEventArgs e) {
|
private void Start(object sender, RoutedEventArgs e) {
|
||||||
var stream = new FileStream(App.InteractiveRebaseTodo, FileMode.Create);
|
var temp = Path.GetTempFileName();
|
||||||
|
var stream = new FileStream(temp, FileMode.Create);
|
||||||
var writer = new StreamWriter(stream);
|
var writer = new StreamWriter(stream);
|
||||||
|
|
||||||
for (int i = Items.Count - 1; i >= 0; i--) {
|
for (int i = Items.Count - 1; i >= 0; i--) {
|
||||||
|
@ -263,19 +266,19 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
switch ((InteractiveRebaseMode)item.Mode) {
|
switch ((InteractiveRebaseMode)item.Mode) {
|
||||||
case InteractiveRebaseMode.Pick:
|
case InteractiveRebaseMode.Pick:
|
||||||
writer.WriteLine($"pick {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"p {item.Commit.ShortSHA} {item.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Reword:
|
case InteractiveRebaseMode.Reword:
|
||||||
writer.WriteLine($"reword {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"r {item.Commit.ShortSHA} {item.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Squash:
|
case InteractiveRebaseMode.Squash:
|
||||||
writer.WriteLine($"squash {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"s {item.Commit.ShortSHA} {item.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Fixup:
|
case InteractiveRebaseMode.Fixup:
|
||||||
writer.WriteLine($"fixup {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"f {item.Commit.ShortSHA} {item.Subject}");
|
||||||
break;
|
break;
|
||||||
case InteractiveRebaseMode.Drop:
|
case InteractiveRebaseMode.Drop:
|
||||||
writer.WriteLine($"drop {item.Commit.ShortSHA} {item.Subject}");
|
writer.WriteLine($"d {item.Commit.ShortSHA} {item.Subject}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +289,8 @@ namespace SourceGit.UI {
|
||||||
stream.Close();
|
stream.Close();
|
||||||
|
|
||||||
repo.SetWatcherEnabled(false);
|
repo.SetWatcherEnabled(false);
|
||||||
var errs = repo.RunCommand($"-c sequence.editor=\"\\\"{App.InteractiveRebaseScript}\\\"\" rebase -i {from}^", null);
|
var editor = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
|
var errs = repo.RunCommand($"-c sequence.editor=\"\\\"{editor}\\\" --interactive-rebase \\\"{temp}\\\"\" rebase -i {from}^", null);
|
||||||
repo.AssertCommand(errs);
|
repo.AssertCommand(errs);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace SourceGit.UI {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadMergeMessage() {
|
public void LoadMergeMessage() {
|
||||||
if (string.IsNullOrEmpty(txtCommitMsg.Text)) {
|
if (string.IsNullOrEmpty(txtCommitMsg.Text)) {
|
||||||
var mergeMsgFile = Path.Combine(Repo.Path, ".git", "MERGE_MSG");
|
var mergeMsgFile = Path.Combine(Repo.GitDir, "MERGE_MSG");
|
||||||
if (!File.Exists(mergeMsgFile)) return;
|
if (!File.Exists(mergeMsgFile)) return;
|
||||||
|
|
||||||
var content = File.ReadAllText(mergeMsgFile);
|
var content = File.ReadAllText(mergeMsgFile);
|
||||||
|
|
Loading…
Reference in a new issue