示例#1
0
        public static void SetOriginToSsh(this LocalRepo localRepo)
        {
            if (localRepo.RemoteRepo is null)
            {
                throw new Exception($"remote repo not found for {localRepo}");
            }

            var url = localRepo.RemoteRepo.SshUrl;

            if (url is null)
            {
                throw new Exception($"ssh url is null for {localRepo}");
            }

            SetOriginUrl(localRepo, url, url);
        }
示例#2
0
        public static IDisposable ToggleHttpsUrl(this LocalRepo localRepo)
        {
            // LibGit2Sharp does not support ssh at this time
            // so we'll need to switch to https for any operations with a remote

            var remote = GetOrigin(localRepo);

            if (remote == null)
            {
                throw new Exception($"origin not specified for {localRepo.Name}.  add an origin or reclone this repo.");
            }

            if (remote.Url.StartsWith("http") && remote.PushUrl.StartsWith("http"))
            {
                return(new DisposableAction(null));
            }

            if (localRepo.RemoteRepo is null)
            {
                throw new Exception($"remote repo not found for {localRepo}");
            }

            var httpsUrl = localRepo.RemoteRepo.HttpUrl;

            if (httpsUrl == null)
            {
                throw new Exception($"http url is null for {localRepo}");
            }

            var originalUrl     = remote.Url;
            var originalPushUrl = remote.PushUrl;

            SetOriginUrl(localRepo, httpsUrl, httpsUrl);

            return(new DisposableAction(() => SetOriginUrl(localRepo, originalUrl, originalPushUrl)));
        }
示例#3
0
 public static Remote GetOrigin(this LocalRepo localRepo)
 {
     return(localRepo.GitRepo !.Network.Remotes["origin"]);
 }