mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
Fetch only added remote; Show remote has no branches
This commit is contained in:
parent
9691fd33a8
commit
dbd7a13705
2 changed files with 1093 additions and 1081 deletions
|
@ -1,97 +1,97 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Git {
|
namespace SourceGit.Git {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Git remote
|
/// Git remote
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Remote {
|
public class Remote {
|
||||||
private static readonly Regex FORMAT = new Regex(@"^([\w\.\-]+)\s*(\S+).*$");
|
private static readonly Regex FORMAT = new Regex(@"^([\w\.\-]+)\s*(\S+).*$");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of this remote
|
/// Name of this remote
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// URL
|
/// URL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string URL { get; set; }
|
public string URL { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parsing remote
|
/// Parsing remote
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo">Repository</param>
|
/// <param name="repo">Repository</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static List<Remote> Load(Repository repo) {
|
public static List<Remote> Load(Repository repo) {
|
||||||
var remotes = new List<Remote>();
|
var remotes = new List<Remote>();
|
||||||
var added = new List<string>();
|
var added = new List<string>();
|
||||||
|
|
||||||
repo.RunCommand("remote -v", data => {
|
repo.RunCommand("remote -v", data => {
|
||||||
var match = FORMAT.Match(data);
|
var match = FORMAT.Match(data);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var remote = new Remote() {
|
var remote = new Remote() {
|
||||||
Name = match.Groups[1].Value,
|
Name = match.Groups[1].Value,
|
||||||
URL = match.Groups[2].Value,
|
URL = match.Groups[2].Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (added.Contains(remote.Name)) return;
|
if (added.Contains(remote.Name)) return;
|
||||||
|
|
||||||
added.Add(remote.Name);
|
added.Add(remote.Name);
|
||||||
remotes.Add(remote);
|
remotes.Add(remote);
|
||||||
});
|
});
|
||||||
|
|
||||||
return remotes;
|
return remotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add new remote
|
/// Add new remote
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public static void Add(Repository repo, string name, string url) {
|
public static void Add(Repository repo, string name, string url) {
|
||||||
var errs = repo.RunCommand($"remote add {name} {url}", null);
|
var errs = repo.RunCommand($"remote add {name} {url}", null);
|
||||||
if (errs != null) {
|
if (errs != null) {
|
||||||
App.RaiseError(errs);
|
App.RaiseError(errs);
|
||||||
} else {
|
} else {
|
||||||
repo.Fetch(null, true, null);
|
repo.Fetch(new Remote() { Name = name }, true, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete remote.
|
/// Delete remote.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
/// <param name="remote"></param>
|
/// <param name="remote"></param>
|
||||||
public static void Delete(Repository repo, string remote) {
|
public static void Delete(Repository repo, string remote) {
|
||||||
var errs = repo.RunCommand($"remote remove {remote}", null);
|
var errs = repo.RunCommand($"remote remove {remote}", null);
|
||||||
if (errs != null) App.RaiseError(errs);
|
if (errs != null) App.RaiseError(errs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Edit remote.
|
/// Edit remote.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public void Edit(Repository repo, string name, string url) {
|
public void Edit(Repository repo, string name, string url) {
|
||||||
string errs = null;
|
string errs = null;
|
||||||
|
|
||||||
if (name != Name) {
|
if (name != Name) {
|
||||||
errs = repo.RunCommand($"remote rename {Name} {name}", null);
|
errs = repo.RunCommand($"remote rename {Name} {name}", null);
|
||||||
if (errs != null) {
|
if (errs != null) {
|
||||||
App.RaiseError(errs);
|
App.RaiseError(errs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != URL) {
|
if (url != URL) {
|
||||||
errs = repo.RunCommand($"remote set-url {name} {url}", null);
|
errs = repo.RunCommand($"remote set-url {name} {url}", null);
|
||||||
if (errs != null) App.RaiseError(errs);
|
if (errs != null) App.RaiseError(errs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue