git: Pass auth info to objects that need it instead of global
This commit is contained in:
parent
c677df8c51
commit
c7a2e163b3
|
@ -22,7 +22,6 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using Sparkles;
|
using Sparkles;
|
||||||
using Sparkles.Git;
|
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
@ -213,7 +212,7 @@ namespace SparkleShare {
|
||||||
public virtual void Initialize ()
|
public virtual void Initialize ()
|
||||||
{
|
{
|
||||||
Logger.LogInfo ("Environment", "SparkleShare " + InstallationInfo.Version);
|
Logger.LogInfo ("Environment", "SparkleShare " + InstallationInfo.Version);
|
||||||
Logger.LogInfo ("Environment", "Git " + GitCommand.GitVersion);
|
Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion);
|
||||||
Logger.LogInfo ("Environment", InstallationInfo.Platform + " (" + Environment.OSVersion + ")");
|
Logger.LogInfo ("Environment", InstallationInfo.Platform + " (" + Environment.OSVersion + ")");
|
||||||
|
|
||||||
Preset.PresetsPath = PresetsPath;
|
Preset.PresetsPath = PresetsPath;
|
||||||
|
@ -391,13 +390,13 @@ namespace SparkleShare {
|
||||||
void AddRepository (string folder_path)
|
void AddRepository (string folder_path)
|
||||||
{
|
{
|
||||||
BaseRepository repo = null;
|
BaseRepository repo = null;
|
||||||
string folder_name = Path.GetFileName (folder_path);
|
string folder_name = Path.GetFileName (folder_path);
|
||||||
string backend = Config.GetBackendForFolder (folder_name);
|
string backend = Config.GetBackendForFolder (folder_name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
repo = (BaseRepository) Activator.CreateInstance (
|
repo = (BaseRepository) Activator.CreateInstance (
|
||||||
Type.GetType ("Sparkles." + backend + "." + backend + "Repository, Sparkles." + backend),
|
Type.GetType ("Sparkles." + backend + "." + backend + "Repository, Sparkles." + backend),
|
||||||
new object [] { folder_path, Config });
|
new object [] { folder_path, Config, SSHAuthenticationInfo.DefaultAuthenticationInfo });
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.LogInfo ("Controller", "Failed to load backend '" + backend + "' for '" + folder_name + "': ", e);
|
Logger.LogInfo ("Controller", "Failed to load backend '" + backend + "' for '" + folder_name + "': ", e);
|
||||||
|
|
|
@ -156,9 +156,7 @@ namespace Sparkles {
|
||||||
Logger.LogInfo ("Fetcher", "Finished");
|
Logger.LogInfo ("Fetcher", "Finished");
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
|
bool repo_is_encrypted = RemoteUrl.AbsolutePath.Contains ("-crypto");
|
||||||
bool repo_is_encrypted = (RemoteUrl.AbsolutePath.Contains ("-crypto") ||
|
|
||||||
RemoteUrl.Host.Equals ("sparkleshare.net"));
|
|
||||||
|
|
||||||
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
|
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,12 @@ namespace Sparkles {
|
||||||
public readonly string LocalPath;
|
public readonly string LocalPath;
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public readonly Uri RemoteUrl;
|
public readonly Uri RemoteUrl;
|
||||||
public List<ChangeSet> ChangeSets { get; private set; }
|
public List<ChangeSet> ChangeSets { get; set; }
|
||||||
public SyncStatus Status { get; private set; }
|
public SyncStatus Status { get; set; }
|
||||||
public ErrorStatus Error { get; protected set; }
|
public ErrorStatus Error { get; protected set; }
|
||||||
public bool IsBuffering { get; private set; }
|
public bool IsBuffering { get; set; }
|
||||||
public double ProgressPercentage { get; private set; }
|
public double ProgressPercentage { get; set; }
|
||||||
public double ProgressSpeed { get; private set; }
|
public double ProgressSpeed { get; set; }
|
||||||
|
|
||||||
public DateTime LastSync {
|
public DateTime LastSync {
|
||||||
get {
|
get {
|
||||||
|
@ -132,21 +132,20 @@ namespace Sparkles {
|
||||||
|
|
||||||
protected Configuration local_config;
|
protected Configuration local_config;
|
||||||
|
|
||||||
|
string identifier;
|
||||||
|
BaseListener listener;
|
||||||
|
Watcher watcher;
|
||||||
|
TimeSpan poll_interval = PollInterval.Short;
|
||||||
|
DateTime last_poll = DateTime.Now;
|
||||||
|
DateTime progress_last_change = DateTime.Now;
|
||||||
|
Timers.Timer remote_timer = new Timers.Timer () { Interval = 5000 };
|
||||||
|
DisconnectReason last_disconnect_reason = DisconnectReason.None;
|
||||||
|
|
||||||
private string identifier;
|
bool is_syncing {
|
||||||
private BaseListener listener;
|
|
||||||
private Watcher watcher;
|
|
||||||
private TimeSpan poll_interval = PollInterval.Short;
|
|
||||||
private DateTime last_poll = DateTime.Now;
|
|
||||||
private DateTime progress_last_change = DateTime.Now;
|
|
||||||
private Timers.Timer remote_timer = new Timers.Timer () { Interval = 5000 };
|
|
||||||
private DisconnectReason last_disconnect_reason = DisconnectReason.None;
|
|
||||||
|
|
||||||
private bool is_syncing {
|
|
||||||
get { return (Status == SyncStatus.SyncUp || Status == SyncStatus.SyncDown || IsBuffering); }
|
get { return (Status == SyncStatus.SyncUp || Status == SyncStatus.SyncDown || IsBuffering); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PollInterval {
|
static class PollInterval {
|
||||||
public static readonly TimeSpan Short = new TimeSpan (0, 0, 5, 0);
|
public static readonly TimeSpan Short = new TimeSpan (0, 0, 5, 0);
|
||||||
public static readonly TimeSpan Long = new TimeSpan (0, 0, 15, 0);
|
public static readonly TimeSpan Long = new TimeSpan (0, 0, 15, 0);
|
||||||
}
|
}
|
||||||
|
@ -182,7 +181,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void RemoteTimerElapsedDelegate (object sender, EventArgs args)
|
void RemoteTimerElapsedDelegate (object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
if (this.is_syncing || IsBuffering || Status == SyncStatus.Paused)
|
if (this.is_syncing || IsBuffering || Status == SyncStatus.Paused)
|
||||||
return;
|
return;
|
||||||
|
@ -239,7 +238,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object buffer_lock = new Object ();
|
Object buffer_lock = new Object ();
|
||||||
|
|
||||||
public void OnFileActivity (FileSystemEventArgs args)
|
public void OnFileActivity (FileSystemEventArgs args)
|
||||||
{
|
{
|
||||||
|
@ -355,7 +354,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SyncUpBase ()
|
void SyncUpBase ()
|
||||||
{
|
{
|
||||||
if (!UseCustomWatcher)
|
if (!UseCustomWatcher)
|
||||||
this.watcher.Disable ();
|
this.watcher.Disable ();
|
||||||
|
@ -411,7 +410,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SyncDownBase ()
|
void SyncDownBase ()
|
||||||
{
|
{
|
||||||
if (!UseCustomWatcher)
|
if (!UseCustomWatcher)
|
||||||
this.watcher.Disable ();
|
this.watcher.Disable ();
|
||||||
|
@ -484,7 +483,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void CreateListener ()
|
void CreateListener ()
|
||||||
{
|
{
|
||||||
this.listener = ListenerFactory.CreateListener (Name, Identifier);
|
this.listener = ListenerFactory.CreateListener (Name, Identifier);
|
||||||
|
|
||||||
|
@ -500,7 +499,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ListenerConnectedDelegate ()
|
void ListenerConnectedDelegate ()
|
||||||
{
|
{
|
||||||
if (this.last_disconnect_reason == DisconnectReason.SystemSleep) {
|
if (this.last_disconnect_reason == DisconnectReason.SystemSleep) {
|
||||||
this.last_disconnect_reason = DisconnectReason.None;
|
this.last_disconnect_reason = DisconnectReason.None;
|
||||||
|
@ -513,7 +512,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ListenerDisconnectedDelegate (DisconnectReason reason)
|
void ListenerDisconnectedDelegate (DisconnectReason reason)
|
||||||
{
|
{
|
||||||
Logger.LogInfo (Name, "Falling back to regular polling");
|
Logger.LogInfo (Name, "Falling back to regular polling");
|
||||||
this.poll_interval = PollInterval.Short;
|
this.poll_interval = PollInterval.Short;
|
||||||
|
@ -538,7 +537,7 @@ namespace Sparkles {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ListenerAnnouncementReceivedDelegate (Announcement announcement)
|
void ListenerAnnouncementReceivedDelegate (Announcement announcement)
|
||||||
{
|
{
|
||||||
string identifier = Identifier;
|
string identifier = Identifier;
|
||||||
|
|
||||||
|
@ -560,7 +559,7 @@ namespace Sparkles {
|
||||||
|
|
||||||
|
|
||||||
// Recursively gets a folder's size in bytes
|
// Recursively gets a folder's size in bytes
|
||||||
private long CalculateSize (DirectoryInfo parent)
|
long CalculateSize (DirectoryInfo parent)
|
||||||
{
|
{
|
||||||
if (ExcludePaths.Contains (parent.Name))
|
if (ExcludePaths.Contains (parent.Name))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
namespace Sparkles.Git {
|
namespace Sparkles.Git {
|
||||||
|
@ -20,10 +21,25 @@ namespace Sparkles.Git {
|
||||||
public class GitCommand : Command {
|
public class GitCommand : Command {
|
||||||
|
|
||||||
public static string SSHPath;
|
public static string SSHPath;
|
||||||
public static string GitPath;
|
|
||||||
public static string ExecPath;
|
public static string ExecPath;
|
||||||
|
|
||||||
|
|
||||||
|
static string git_path;
|
||||||
|
|
||||||
|
public static string GitPath {
|
||||||
|
get {
|
||||||
|
if (git_path == null)
|
||||||
|
git_path = LocateCommand ("git");
|
||||||
|
|
||||||
|
return git_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
git_path = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static string GitVersion {
|
public static string GitVersion {
|
||||||
get {
|
get {
|
||||||
if (GitPath == null)
|
if (GitPath == null)
|
||||||
|
@ -35,27 +51,32 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GitCommand (string path, string args) : base (path, args)
|
public GitCommand (string working_dir, string args) : this (working_dir, args, null)
|
||||||
{
|
{
|
||||||
if (GitPath == null)
|
}
|
||||||
GitPath = LocateCommand ("git");
|
|
||||||
|
|
||||||
StartInfo.FileName = GitPath;
|
|
||||||
StartInfo.WorkingDirectory = path;
|
public GitCommand (string working_dir, string args, SSHAuthenticationInfo auth_info) : base (GitPath, args)
|
||||||
|
{
|
||||||
|
StartInfo.WorkingDirectory = working_dir;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty (SSHPath))
|
if (string.IsNullOrEmpty (SSHPath))
|
||||||
SSHPath = "ssh";
|
SSHPath = "ssh";
|
||||||
|
|
||||||
string GIT_SSH_COMMAND = SSHPath + " " +
|
string GIT_SSH_COMMAND = SSHPath;
|
||||||
"-i \"" + SSHAuthenticationInfo.DefaultAuthenticationInfo.PrivateKeyFilePath + "\" " +
|
|
||||||
"-o UserKnownHostsFile=\"" + SSHAuthenticationInfo.DefaultAuthenticationInfo.KnownHostsFilePath + "\" " +
|
if (auth_info != null) {
|
||||||
"-o PasswordAuthentication=no " +
|
GIT_SSH_COMMAND = SSHPath + " " +
|
||||||
"-F /dev/null"; // Ignore the environment's SSH config file
|
"-i \"" + auth_info.PrivateKeyFilePath + "\" " +
|
||||||
|
"-o UserKnownHostsFile=\"" + auth_info.KnownHostsFilePath + "\" " +
|
||||||
|
"-o PasswordAuthentication=no " +
|
||||||
|
"-F /dev/null"; // Ignore the environment's SSH config file
|
||||||
|
}
|
||||||
|
|
||||||
if (ExecPath == null)
|
if (ExecPath == null)
|
||||||
SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath);
|
SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath);
|
||||||
|
|
||||||
SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND);
|
SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND);
|
||||||
SetEnvironmentVariable ("GIT_TERMINAL_PROMPT", "0");
|
SetEnvironmentVariable ("GIT_TERMINAL_PROMPT", "0");
|
||||||
SetEnvironmentVariable ("LANG", "en_US");
|
SetEnvironmentVariable ("LANG", "en_US");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
public class GitFetcher : SSHFetcher {
|
public class GitFetcher : SSHFetcher {
|
||||||
|
|
||||||
|
SSHAuthenticationInfo auth_info;
|
||||||
GitCommand git;
|
GitCommand git;
|
||||||
|
|
||||||
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||||
|
@ -43,8 +44,10 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GitFetcher (SparkleFetcherInfo info) : base (info)
|
public GitFetcher (SparkleFetcherInfo fetcher_info, SSHAuthenticationInfo auth_info) : base (fetcher_info)
|
||||||
{
|
{
|
||||||
|
this.auth_info = auth_info;
|
||||||
|
|
||||||
if (RemoteUrl.ToString ().StartsWith ("ssh+"))
|
if (RemoteUrl.ToString ().StartsWith ("ssh+"))
|
||||||
RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://")));
|
RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://")));
|
||||||
|
|
||||||
|
@ -92,11 +95,11 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
if (FetchPriorHistory) {
|
if (FetchPriorHistory) {
|
||||||
this.git = new GitCommand (Configuration.DefaultConfig.TmpPath,
|
this.git = new GitCommand (Configuration.DefaultConfig.TmpPath,
|
||||||
"clone --progress --no-checkout \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
"clone --progress --no-checkout \"" + RemoteUrl + "\" \"" + TargetFolder + "\"", auth_info);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.git = new GitCommand (Configuration.DefaultConfig.TmpPath,
|
this.git = new GitCommand (Configuration.DefaultConfig.TmpPath,
|
||||||
"clone --progress --no-checkout --depth=1 \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
"clone --progress --no-checkout --depth=1 \"" + RemoteUrl + "\" \"" + TargetFolder + "\"", auth_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.git.StartInfo.RedirectStandardError = true;
|
this.git.StartInfo.RedirectStandardError = true;
|
||||||
|
|
|
@ -27,33 +27,34 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
public class GitRepository : BaseRepository {
|
public class GitRepository : BaseRepository {
|
||||||
|
|
||||||
private bool user_is_set;
|
SSHAuthenticationInfo auth_info;
|
||||||
private bool is_encrypted;
|
bool user_is_set;
|
||||||
|
bool is_encrypted;
|
||||||
|
|
||||||
private string cached_branch;
|
string cached_branch;
|
||||||
|
|
||||||
private Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||||
private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
||||||
|
|
||||||
private Regex log_regex = new Regex (@"commit ([a-f0-9]{40})*\n" +
|
Regex log_regex = new Regex (@"commit ([a-f0-9]{40})*\n" +
|
||||||
"Author: (.+) <(.+)>\n" +
|
"Author: (.+) <(.+)>\n" +
|
||||||
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
|
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
|
||||||
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
|
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
|
||||||
"*", RegexOptions.Compiled);
|
"*", RegexOptions.Compiled);
|
||||||
|
|
||||||
private Regex merge_regex = new Regex (@"commit ([a-f0-9]{40})\n" +
|
Regex merge_regex = new Regex (@"commit ([a-f0-9]{40})\n" +
|
||||||
"Merge: [a-f0-9]{7} [a-f0-9]{7}\n" +
|
"Merge: [a-f0-9]{7} [a-f0-9]{7}\n" +
|
||||||
"Author: (.+) <(.+)>\n" +
|
"Author: (.+) <(.+)>\n" +
|
||||||
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
|
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
|
||||||
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
|
"([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
|
||||||
"*", RegexOptions.Compiled);
|
"*", RegexOptions.Compiled);
|
||||||
|
|
||||||
private string branch {
|
string branch {
|
||||||
get {
|
get {
|
||||||
if (!string.IsNullOrEmpty (this.cached_branch))
|
if (!string.IsNullOrEmpty (this.cached_branch))
|
||||||
return this.cached_branch;
|
return this.cached_branch;
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "config core.ignorecase true");
|
var git = new GitCommand (LocalPath, "config core.ignorecase true");
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
while (this.in_merge && HasLocalChanges) {
|
while (this.in_merge && HasLocalChanges) {
|
||||||
|
@ -76,7 +77,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool in_merge {
|
bool in_merge {
|
||||||
get {
|
get {
|
||||||
string merge_file_path = Path.Combine (LocalPath, ".git", "MERGE_HEAD");
|
string merge_file_path = Path.Combine (LocalPath, ".git", "MERGE_HEAD");
|
||||||
return File.Exists (merge_file_path);
|
return File.Exists (merge_file_path);
|
||||||
|
@ -84,9 +85,11 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GitRepository (string path, Configuration config) : base (path, config)
|
public GitRepository (string path, Configuration config, SSHAuthenticationInfo auth_info) : base (path, config)
|
||||||
{
|
{
|
||||||
GitCommand git = new GitCommand (LocalPath, "config core.ignorecase false");
|
this.auth_info = auth_info;
|
||||||
|
|
||||||
|
var git = new GitCommand (LocalPath, "config core.ignorecase false");
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
git = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
|
git = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
|
||||||
|
@ -139,7 +142,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void UpdateSizes ()
|
void UpdateSizes ()
|
||||||
{
|
{
|
||||||
double size = CalculateSizes (new DirectoryInfo (LocalPath));
|
double size = CalculateSizes (new DirectoryInfo (LocalPath));
|
||||||
double history_size = CalculateSizes (new DirectoryInfo (Path.Combine (LocalPath, ".git")));
|
double history_size = CalculateSizes (new DirectoryInfo (Path.Combine (LocalPath, ".git")));
|
||||||
|
@ -154,13 +157,13 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
public override string CurrentRevision {
|
public override string CurrentRevision {
|
||||||
get {
|
get {
|
||||||
GitCommand git = new GitCommand (LocalPath, "rev-parse HEAD");
|
var git = new GitCommand (LocalPath, "rev-parse HEAD");
|
||||||
string output = git.StartAndReadStandardOutput ();
|
string output = git.StartAndReadStandardOutput ();
|
||||||
|
|
||||||
if (git.ExitCode == 0)
|
if (git.ExitCode == 0)
|
||||||
return output;
|
return output;
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +173,9 @@ namespace Sparkles.Git {
|
||||||
Logger.LogInfo ("Git", Name + " | Checking for remote changes...");
|
Logger.LogInfo ("Git", Name + " | Checking for remote changes...");
|
||||||
string current_revision = CurrentRevision;
|
string current_revision = CurrentRevision;
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "ls-remote --heads --exit-code \"" + RemoteUrl + "\" " + this.branch);
|
var git = new GitCommand (LocalPath,
|
||||||
|
"ls-remote --heads --exit-code \"" + RemoteUrl + "\" " + this.branch, auth_info);
|
||||||
|
|
||||||
string output = git.StartAndReadStandardOutput ();
|
string output = git.StartAndReadStandardOutput ();
|
||||||
|
|
||||||
if (git.ExitCode != 0)
|
if (git.ExitCode != 0)
|
||||||
|
@ -216,7 +221,7 @@ namespace Sparkles.Git {
|
||||||
if (message != null)
|
if (message != null)
|
||||||
Commit (message);
|
Commit (message);
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch);
|
var git = new GitCommand (LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch, auth_info);
|
||||||
git.StartInfo.RedirectStandardError = true;
|
git.StartInfo.RedirectStandardError = true;
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
|
@ -287,7 +292,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
public override bool SyncDown ()
|
public override bool SyncDown ()
|
||||||
{
|
{
|
||||||
GitCommand git = new GitCommand (LocalPath, "fetch --progress \"" + RemoteUrl + "\" " + this.branch);
|
var git = new GitCommand (LocalPath, "fetch --progress \"" + RemoteUrl + "\" " + this.branch, auth_info);
|
||||||
|
|
||||||
git.StartInfo.RedirectStandardError = true;
|
git.StartInfo.RedirectStandardError = true;
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
@ -367,7 +372,7 @@ namespace Sparkles.Git {
|
||||||
get {
|
get {
|
||||||
PrepareDirectories (LocalPath);
|
PrepareDirectories (LocalPath);
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "status --porcelain");
|
var git = new GitCommand (LocalPath, "status --porcelain");
|
||||||
string output = git.StartAndReadStandardOutput ();
|
string output = git.StartAndReadStandardOutput ();
|
||||||
|
|
||||||
return !string.IsNullOrEmpty (output);
|
return !string.IsNullOrEmpty (output);
|
||||||
|
@ -393,9 +398,9 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
|
|
||||||
// Stages the made changes
|
// Stages the made changes
|
||||||
private bool Add ()
|
bool Add ()
|
||||||
{
|
{
|
||||||
GitCommand git = new GitCommand (LocalPath, "add --all");
|
var git = new GitCommand (LocalPath, "add --all");
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
return (git.ExitCode == 0);
|
return (git.ExitCode == 0);
|
||||||
|
@ -403,7 +408,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
|
|
||||||
// Commits the made changes
|
// Commits the made changes
|
||||||
private void Commit (string message)
|
void Commit (string message)
|
||||||
{
|
{
|
||||||
GitCommand git;
|
GitCommand git;
|
||||||
|
|
||||||
|
@ -425,7 +430,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
private bool Merge ()
|
bool Merge ()
|
||||||
{
|
{
|
||||||
string message = FormatCommitMessage ();
|
string message = FormatCommitMessage ();
|
||||||
|
|
||||||
|
@ -493,7 +498,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ResolveConflict ()
|
void ResolveConflict ()
|
||||||
{
|
{
|
||||||
// This is a list of conflict status codes that Git uses, their
|
// This is a list of conflict status codes that Git uses, their
|
||||||
// meaning, and how SparkleShare should handle them.
|
// meaning, and how SparkleShare should handle them.
|
||||||
|
@ -507,7 +512,7 @@ namespace Sparkles.Git {
|
||||||
// UU unmerged, both modified -> Use server's, save ours as a timestamped copy
|
// UU unmerged, both modified -> Use server's, save ours as a timestamped copy
|
||||||
// ?? unmerged, new files -> Stage the new files
|
// ?? unmerged, new files -> Stage the new files
|
||||||
|
|
||||||
GitCommand git_status = new GitCommand (LocalPath, "status --porcelain");
|
var git_status = new GitCommand (LocalPath, "status --porcelain");
|
||||||
string output = git_status.StartAndReadStandardOutput ();
|
string output = git_status.StartAndReadStandardOutput ();
|
||||||
|
|
||||||
string [] lines = output.Split ("\n".ToCharArray ());
|
string [] lines = output.Split ("\n".ToCharArray ());
|
||||||
|
@ -534,7 +539,7 @@ namespace Sparkles.Git {
|
||||||
Logger.LogInfo ("Git", Name + " | Ignoring conflict in special file: " + conflicting_path);
|
Logger.LogInfo ("Git", Name + " | Ignoring conflict in special file: " + conflicting_path);
|
||||||
|
|
||||||
// Recover local version
|
// Recover local version
|
||||||
GitCommand git_ours = new GitCommand (LocalPath, "checkout --ours \"" + conflicting_path + "\"");
|
var git_ours = new GitCommand (LocalPath, "checkout --ours \"" + conflicting_path + "\"");
|
||||||
git_ours.StartAndWaitForExit ();
|
git_ours.StartAndWaitForExit ();
|
||||||
|
|
||||||
string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path);
|
string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path);
|
||||||
|
@ -552,7 +557,7 @@ namespace Sparkles.Git {
|
||||||
line.StartsWith ("AU") || line.StartsWith ("UA")) {
|
line.StartsWith ("AU") || line.StartsWith ("UA")) {
|
||||||
|
|
||||||
// Recover local version
|
// Recover local version
|
||||||
GitCommand git_ours = new GitCommand (LocalPath, "checkout --ours \"" + conflicting_path + "\"");
|
var git_ours = new GitCommand (LocalPath, "checkout --ours \"" + conflicting_path + "\"");
|
||||||
git_ours.StartAndWaitForExit ();
|
git_ours.StartAndWaitForExit ();
|
||||||
|
|
||||||
// Append a timestamp to local version.
|
// Append a timestamp to local version.
|
||||||
|
@ -569,7 +574,7 @@ namespace Sparkles.Git {
|
||||||
File.Move (abs_conflicting_path, abs_our_path);
|
File.Move (abs_conflicting_path, abs_our_path);
|
||||||
|
|
||||||
// Recover server version
|
// Recover server version
|
||||||
GitCommand git_theirs = new GitCommand (LocalPath, "checkout --theirs \"" + conflicting_path + "\"");
|
var git_theirs = new GitCommand (LocalPath, "checkout --theirs \"" + conflicting_path + "\"");
|
||||||
git_theirs.StartAndWaitForExit ();
|
git_theirs.StartAndWaitForExit ();
|
||||||
|
|
||||||
trigger_conflict_event = true;
|
trigger_conflict_event = true;
|
||||||
|
@ -580,7 +585,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
// The modified local version is already in the checkout, so it just needs to be added.
|
// The modified local version is already in the checkout, so it just needs to be added.
|
||||||
// We need to specifically mention the file, so we can't reuse the Add () method
|
// We need to specifically mention the file, so we can't reuse the Add () method
|
||||||
GitCommand git_add = new GitCommand (LocalPath, "add \"" + conflicting_path + "\"");
|
var git_add = new GitCommand (LocalPath, "add \"" + conflicting_path + "\"");
|
||||||
git_add.StartAndWaitForExit ();
|
git_add.StartAndWaitForExit ();
|
||||||
|
|
||||||
|
|
||||||
|
@ -588,7 +593,7 @@ namespace Sparkles.Git {
|
||||||
} else if (line.StartsWith ("UD")) {
|
} else if (line.StartsWith ("UD")) {
|
||||||
|
|
||||||
// Recover server version
|
// Recover server version
|
||||||
GitCommand git_theirs = new GitCommand (LocalPath, "checkout --theirs \"" + conflicting_path + "\"");
|
var git_theirs = new GitCommand (LocalPath, "checkout --theirs \"" + conflicting_path + "\"");
|
||||||
git_theirs.StartAndWaitForExit ();
|
git_theirs.StartAndWaitForExit ();
|
||||||
|
|
||||||
|
|
||||||
|
@ -607,7 +612,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
Add ();
|
Add ();
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "commit --message \"Conflict resolution by SparkleShare\"");
|
var git = new GitCommand (LocalPath, "commit --message \"Conflict resolution by SparkleShare\"");
|
||||||
git.StartInfo.RedirectStandardOutput = false;
|
git.StartInfo.RedirectStandardOutput = false;
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
|
@ -630,7 +635,7 @@ namespace Sparkles.Git {
|
||||||
// files from the index. This is a suboptimal workaround but it does the job
|
// files from the index. This is a suboptimal workaround but it does the job
|
||||||
if (this.is_encrypted) {
|
if (this.is_encrypted) {
|
||||||
// Restore the older file...
|
// Restore the older file...
|
||||||
GitCommand git = new GitCommand (LocalPath, "checkout " + revision + " \"" + path + "\"");
|
var git = new GitCommand (LocalPath, "checkout " + revision + " \"" + path + "\"");
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
string local_file_path = Path.Combine (LocalPath, path);
|
string local_file_path = Path.Combine (LocalPath, path);
|
||||||
|
@ -652,7 +657,7 @@ namespace Sparkles.Git {
|
||||||
} else {
|
} else {
|
||||||
path = path.Replace ("\"", "\\\"");
|
path = path.Replace ("\"", "\\\"");
|
||||||
|
|
||||||
GitCommand git = new GitCommand (LocalPath, "show " + revision + ":\"" + path + "\"");
|
var git = new GitCommand (LocalPath, "show " + revision + ":\"" + path + "\"");
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
FileStream stream = File.OpenWrite (target_file_path);
|
FileStream stream = File.OpenWrite (target_file_path);
|
||||||
|
@ -667,7 +672,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool FindError (string line)
|
bool FindError (string line)
|
||||||
{
|
{
|
||||||
Error = ErrorStatus.None;
|
Error = ErrorStatus.None;
|
||||||
|
|
||||||
|
@ -722,9 +727,9 @@ namespace Sparkles.Git {
|
||||||
return GetChangeSetsInternal (path);
|
return GetChangeSetsInternal (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ChangeSet> GetChangeSetsInternal (string path)
|
List<ChangeSet> GetChangeSetsInternal (string path)
|
||||||
{
|
{
|
||||||
List <ChangeSet> change_sets = new List <ChangeSet> ();
|
var change_sets = new List <ChangeSet> ();
|
||||||
GitCommand git;
|
GitCommand git;
|
||||||
|
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
@ -939,7 +944,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string EnsureSpecialCharacters (string path)
|
string EnsureSpecialCharacters (string path)
|
||||||
{
|
{
|
||||||
// The path is quoted if it contains special characters
|
// The path is quoted if it contains special characters
|
||||||
if (path.StartsWith ("\""))
|
if (path.StartsWith ("\""))
|
||||||
|
@ -949,7 +954,7 @@ namespace Sparkles.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string ResolveSpecialChars (string s)
|
string ResolveSpecialChars (string s)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder (s.Length);
|
StringBuilder builder = new StringBuilder (s.Length);
|
||||||
List<byte> codes = new List<byte> ();
|
List<byte> codes = new List<byte> ();
|
||||||
|
@ -982,7 +987,7 @@ namespace Sparkles.Git {
|
||||||
//
|
//
|
||||||
// It also prevents git repositories from becoming
|
// It also prevents git repositories from becoming
|
||||||
// git submodules by renaming the .git/HEAD file
|
// git submodules by renaming the .git/HEAD file
|
||||||
private void PrepareDirectories (string path)
|
void PrepareDirectories (string path)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
foreach (string child_path in Directory.GetDirectories (path)) {
|
foreach (string child_path in Directory.GetDirectories (path)) {
|
||||||
|
@ -1028,11 +1033,11 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<Change> ParseStatus ()
|
List<Change> ParseStatus ()
|
||||||
{
|
{
|
||||||
List<Change> changes = new List<Change> ();
|
List<Change> changes = new List<Change> ();
|
||||||
|
|
||||||
GitCommand git_status = new GitCommand (LocalPath, "status --porcelain");
|
var git_status = new GitCommand (LocalPath, "status --porcelain");
|
||||||
git_status.Start ();
|
git_status.Start ();
|
||||||
|
|
||||||
while (!git_status.StandardOutput.EndOfStream) {
|
while (!git_status.StandardOutput.EndOfStream) {
|
||||||
|
@ -1078,7 +1083,7 @@ namespace Sparkles.Git {
|
||||||
|
|
||||||
|
|
||||||
// Creates a pretty commit message based on what has changed
|
// Creates a pretty commit message based on what has changed
|
||||||
private string FormatCommitMessage ()
|
string FormatCommitMessage ()
|
||||||
{
|
{
|
||||||
string message = "";
|
string message = "";
|
||||||
|
|
||||||
|
@ -1088,14 +1093,16 @@ namespace Sparkles.Git {
|
||||||
message += "> ‘" + EnsureSpecialCharacters (change.MovedToPath) + "’\n";
|
message += "> ‘" + EnsureSpecialCharacters (change.MovedToPath) + "’\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (change.Type == ChangeType.Edited) {
|
switch (change.Type) {
|
||||||
|
case ChangeType.Edited:
|
||||||
message += "/";
|
message += "/";
|
||||||
|
break;
|
||||||
} else if (change.Type == ChangeType.Deleted) {
|
case ChangeType.Deleted:
|
||||||
message += "-";
|
message += "-";
|
||||||
|
break;
|
||||||
} else if (change.Type == ChangeType.Added) {
|
case ChangeType.Added:
|
||||||
message += "+";
|
message += "+";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
message += " ‘" + change.Path + "’\n";
|
message += " ‘" + change.Path + "’\n";
|
||||||
|
|
Loading…
Reference in a new issue