示例#1
0
        /// <summary>
        /// Initializes a command for use including the repository and output support.
        /// </summary>
        /// <param name="repo">Specifies the repository to use.</param>
        /// <param name="path"></param>
        public void Init(GitSharp.Repository repo, string path)
        {
            try
            {
                //Initialize the output stream for all console-based messages.
                Git.DefaultOutputStream = new StreamWriter(Console.OpenStandardOutput());
                Console.SetOut(Git.DefaultOutputStream);
            }
            catch (IOException)
            {
                throw die("cannot create output stream");
            }

            // Initialize the repository in use.
            if (repo != null)
            {
                GitRepository = repo;
                GitDirectory  = ((Core.Repository)repo).Directory.FullName;
            }
            else
            {
                GitRepository = null;
                GitDirectory  = path;
            }
        }
示例#2
0
        private static GitDetail GetGitDetailCore(string path)
        {
            GitDetail detail = null;

            try
            {
                var repoPath = Repository.FindRepository(path);
                if (string.IsNullOrEmpty(repoPath))
                {
                    // Use local modified date when git repo is not found
                    var time = File.GetLastWriteTimeUtc(path);
                    detail = new GitDetail
                    {
                        CommitDetail = new CommitDetail
                        {
                            Author = new UserInfo
                            {
                                Date = time,
                            }
                        }
                    };
                    return(detail);
                }

                var directory = Path.GetDirectoryName(repoPath);
                var wrapper   = RepoCache.GetOrAdd(directory, s => new RepoWrapper(CoreRepository.Open(s)));
                var repo      = wrapper.Repo;
                path   = PathUtility.MakeRelativePath(directory, path);
                detail = new GitDetail();

                var walker = wrapper.Walker;

                // TODO: Disable fetching commit detail for now until GlobalContext is added
                // var commitDetail = walker.GetCommitDetail(path);
                // detail.CommitDetail = commitDetail;

                // Convert to forward slash
                detail.LocalWorkingDirectory = repo.WorkingDirectory.FullName;
                if (repo.Head == null)
                {
                    return(detail);
                }

                var branch = repo.getBranch();
                detail.RemoteRepositoryUrl = repo.Config.getString("remote", "origin", "url");
                detail.RemoteBranch        = branch;
                detail.RelativePath        = path;
                return(detail);
            }
            catch (Exception e)
            {
                Logger.LogWarning($"Have issue extracting repo detail for {path}: {e.Message}");
            }

            return(detail);
        }
示例#3
0
		public IEnumerable<CommitInfo> ListCommits() {
			using(var repository = new GitSharp.Repository(FullPath)) {
				var w = new RevWalk(repository);
				w.markStart(((GitSharp.Core.Repository)repository).getAllRefsByPeeledObjectId().Keys.Select(w.parseCommit));
				return w.Select(t => new CommitInfo { 
					Id = t.getId().Name,
					Date = t.AsCommit(w).Author.When.MillisToDateTimeOffset(t.AsCommit(w).Author.TimeZoneOffset),
					Message = t.getShortMessage()
				}).ToArray();
			}
		}
示例#4
0
 public IEnumerable <CommitInfo> ListCommits()
 {
     using (var repository = new GitSharp.Repository(FullPath)) {
         var w = new RevWalk(repository);
         w.markStart(((GitSharp.Core.Repository)repository).getAllRefsByPeeledObjectId().Keys.Select(w.parseCommit));
         return(w.Select(t => new CommitInfo {
             Id = t.getId().Name,
             Date = t.AsCommit(w).Author.When.MillisToDateTimeOffset(t.AsCommit(w).Author.TimeZoneOffset),
             Message = t.getShortMessage()
         }).ToArray());
     }
 }
示例#5
0
 public IEnumerable<GitSharp.Commit> GetRecentCommits(int number)
 {
     using (var repository = new GitSharp.Repository(FullPath)) {
         var commit = repository.CurrentBranch.CurrentCommit;
         if (commit == null) return null;
         var recentCommits = new List<GitSharp.Commit> { commit };
         for (var i = 0; i < number; ++i) {
             commit = commit.Parent;
             if (commit == null) break;
             recentCommits.Add(commit);
         }
         return recentCommits;
     }
 }
示例#6
0
		public CommitInfo GetLatestCommit() {
			using (var repository = new GitSharp.Repository(FullPath)) {
				var commit = repository.Head.CurrentCommit;

				if (commit == null) {
					return null;
				}

				return new CommitInfo {
					Id = commit.ShortHash,
					Message = commit.Message,
					Date = commit.CommitDate.DateTime
				};
			}
		}
示例#7
0
        public CommitInfo GetLatestCommit()
        {
            using (var repository = new GitSharp.Repository(FullPath)) {
                var commit = repository.Head.CurrentCommit;

                if (commit == null)
                {
                    return(null);
                }

                return(new CommitInfo {
                    Message = commit.Message,
                    Date = commit.CommitDate.DateTime
                });
            }
        }
示例#8
0
        public bool PollRepositories()
        {
            string url;

            url = "d:\\projects\\bradstest\\.git";

            var git_url = GitSharp.Repository.FindRepository(url);
            if (git_url == null || !GitSharp.Repository.IsValid(git_url))
            {
                Console.Write("Given path doesn't seem to refer to a git repository: " + url);
                return false;
            }
            var repo = new GitSharp.Repository(git_url);
            PollCommitments(repo);
            return true;
        }
        public override CommitInfo GetLatestCommit()
        {
            using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
            {
                var commit = repository.Head.CurrentCommit;

                if (commit == null)
                {
                    return(null);
                }

                return(new CommitInfo
                {
                    Message = commit.Message,
                    Date = commit.CommitDate.LocalDateTime
                });
            }
        }
        public override CommitInfo GetLatestCommit()
        {
            using (var repository = new GitSharp.Repository(PhysicalPathDotGit))
            {
                var commit = repository.Head.CurrentCommit;

                if (commit == null)
                {
                    return null;
                }

                return new CommitInfo
                {
                    Message = commit.Message,
                    Date = commit.CommitDate.LocalDateTime
                };
            }
        }
示例#11
0
        // To keep this simple I only look at the head commit and parse the bugzid.
        void UpdateFogBugz(ReceivePack rp, ICollection<ReceiveCommand> commands)
        {
            using (var gitRepo = new GitSharp.Repository(repository.FullPath))
            {
                var commit = gitRepo.Head.CurrentCommit;

                if (commit != null && commit.Message != null && commit.Message.ToLower().Contains("bugzid:"))
                {
                    var bugzid = ParseBugzId(commit.Message);

                    var hashBase = commit.Hash;

                    foreach (var change in commit.Changes)
                    {
                        if (change == null)
                        {
                            continue;
                        }

                        var fileName = change.Name;

                        var fileOldSha = string.Empty;
                        if (change.ReferenceObject != null)
                        {
                            fileOldSha = change.ReferenceObject.Hash;
                        }

                        var fileNewSha = string.Empty;
                        if (change.ChangedObject != null)
                        {
                            fileNewSha = change.ChangedObject.Hash;
                        }

                        var hashBaseParent = string.Empty;
                        if (change.ReferenceCommit != null)
                        {
                            hashBaseParent = change.ReferenceCommit.Hash;
                        }

                        SubmitData(fileOldSha, hashBaseParent, fileNewSha, hashBase, bugzid, fileName, repository.Name);
                    }
                }
            }
        }
示例#12
0
        // To keep this simple I only look at the head commit and parse the bugzid.
        void UpdateFogBugz(ReceivePack rp, ICollection <ReceiveCommand> commands)
        {
            using (var gitRepo = new GitSharp.Repository(repository.FullPath))
            {
                var commit = gitRepo.Head.CurrentCommit;

                if (commit != null && commit.Message != null && commit.Message.ToLower().Contains("bugzid:"))
                {
                    var bugzid = ParseBugzId(commit.Message);

                    var hashBase = commit.Hash;

                    foreach (var change in commit.Changes)
                    {
                        if (change == null)
                        {
                            continue;
                        }

                        var fileName = change.Name;

                        var fileOldSha = string.Empty;
                        if (change.ReferenceObject != null)
                        {
                            fileOldSha = change.ReferenceObject.Hash;
                        }

                        var fileNewSha = string.Empty;
                        if (change.ChangedObject != null)
                        {
                            fileNewSha = change.ChangedObject.Hash;
                        }

                        var hashBaseParent = string.Empty;
                        if (change.ReferenceCommit != null)
                        {
                            hashBaseParent = change.ReferenceCommit.Hash;
                        }

                        SubmitData(fileOldSha, hashBaseParent, fileNewSha, hashBase, bugzid, fileName, repository.Name);
                    }
                }
            }
        }
示例#13
0
		public void Checkout(string hash) {
			using(var repository = new GitSharp.Repository(FullPath)) {
				repository.CurrentBranch.Reset(hash, GitSharp.ResetBehavior.Hard);
			}
		}
        public ActionResult Add(RepositoryDetailModel model)
        {
            if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfigurationManager.AllowUserRepositoryCreation)
            {
                return RedirectToAction("Unauthorized", "Home");
            }

            if (model != null && !String.IsNullOrEmpty(model.Name))
            {
                model.Name = Regex.Replace(model.Name, @"\s", "");
            }

            if (String.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("Name", Resources.Repository_Add_NameFailure);
            }
            else if (ModelState.IsValid)
            {
                if (RepositoryRepository.Create(ConvertRepositoryDetailModel(model)))
                {
                    string path = Path.Combine(UserConfigurationManager.Repositories, model.Name);
                    if (Directory.Exists(path))
                    {
                        using (GitSharp.Repository repository = new GitSharp.Repository(path))
                        {
                            if (repository.Branches.Count > 0)
                            {
                                TempData["AddSuccess"] = true;
                                return RedirectToAction("Index");
                            }
                            else
                            {
                                RepositoryRepository.Delete(model.Name);
                                ModelState.AddModelError("", Resources.Repository_Add_NoBranches);
                            }
                        }
                    }
                    else
                    {
                        RepositoryRepository.Delete(model.Name);
                        ModelState.AddModelError("", Resources.Repository_Add_DirectoryNotExisting);
                    }
                }
                else
                {
                    ModelState.AddModelError("", Resources.Repository_Create_Failure);
                }
            }
            PopulateEditData();
            return View(model);
        }
示例#15
0
        public bool PollRepositories()
        {
            SqlDataReader reader = null;

            try
            {
                reader = GetRepositories();
                while (reader.Read())
                {
                    var repositoryid = reader["RepositoryId"];
                    string repositoryidstring = repositoryid.ToString();
                    var repositorylocation = reader["RepositoryLocation"];
                    string repositorylocationstring = repositorylocation.ToString();

                    var git_url = GitSharp.Repository.FindRepository(repositorylocationstring);
                    if (git_url == null || !GitSharp.Repository.IsValid(git_url))
                    {
                        Console.Write("Given path doesn't seem to refer to a git repository: " + repositorylocation);
                        return false;
                    }
                    var repo = new GitSharp.Repository(git_url);
                    PollCommitments(repo, repositoryidstring);
                }
            }
            catch (System.Exception ex)
            {
                string exmessage = ex.Message;
                //log the exception
            }
            return true;
        }
示例#16
0
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {

                CommandCatalog catalog = new CommandCatalog();
                CommandRef subcommand = catalog.Get(argv[0]);
                string gitdir = null;

                if (subcommand != null)
                {
                    TextBuiltin cmd = subcommand.Create();
                    List<String> args = argv.ToList();
                    GitSharp.Repository repo = null;

                    try
                    {
                        for (int x = 0; x < args.Count; x++)
                        {
                            if (args[x].IndexOf("--git-dir=") > -1)
                            {
                                if (args[x].Length > 10)
                                {
                                    gitdir = args[x].Substring(10);
                                    args.RemoveAt(x);
                                    break;
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.WriteLine("error: can't find git directory");
                            Git.DefaultOutputStream.Flush();
                        }
                        Exit(1);
                    }

                    if (cmd.RequiresRepository)
                    {
                        if (gitdir == null)
                        {
                            gitdir = Commands.AbstractCommand.FindGitDirectory(null, true, false);
                            if (gitdir == null)
                            {
                                Console.Error.WriteLine("fatal: Not a git repository (or any of the parent directories): .git");
                                Exit(0);
                            }
                        }

                        repo = new GitSharp.Repository(gitdir);
                        cmd.Init(repo, gitdir);
                    }
                    else
                        cmd.Init(null, gitdir);

                    try
                    {
                        // Remove the subcommand from the command line
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Git.DefaultOutputStream != null)
                            Git.DefaultOutputStream.Flush();

                        if (repo != null)
                            repo.Close();
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                        ShowHelp();
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    options.Parse(argv, out arguments);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }
示例#17
0
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {
                CommandCatalog catalog    = new CommandCatalog();
                CommandRef     subcommand = catalog.Get(argv[0]);
                string         gitdir     = null;

                if (subcommand != null)
                {
                    TextBuiltin         cmd  = subcommand.Create();
                    List <String>       args = argv.ToList();
                    GitSharp.Repository repo = null;

                    try
                    {
                        for (int x = 0; x < args.Count; x++)
                        {
                            if (args[x].IndexOf("--git-dir=") > -1)
                            {
                                if (args[x].Length > 10)
                                {
                                    gitdir = args[x].Substring(10);
                                    args.RemoveAt(x);
                                    break;
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.WriteLine("error: can't find git directory");
                            Git.DefaultOutputStream.Flush();
                        }
                        Exit(1);
                    }

                    if (cmd.RequiresRepository)
                    {
                        if (gitdir == null)
                        {
                            gitdir = Commands.AbstractCommand.FindGitDirectory(null, true, false);
                            if (gitdir == null)
                            {
                                Console.Error.WriteLine("fatal: Not a git repository (or any of the parent directories): .git");
                                Exit(0);
                            }
                        }

                        repo = new GitSharp.Repository(gitdir);
                        cmd.Init(repo, gitdir);
                    }
                    else
                    {
                        cmd.Init(null, gitdir);
                    }

                    try
                    {
                        // Remove the subcommand from the command line
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.Flush();
                        }

                        if (repo != null)
                        {
                            repo.Close();
                        }
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                    {
                        ShowHelp();
                    }
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    options.Parse(argv, out arguments);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }
 public void Init(GitSharp.Repository repository)
 {
     configurationList.ItemsSource = repository.Config;
 }
示例#19
0
        private void CreatePachagesAsync(object sender, DoWorkEventArgs e)
        {
            ScriptsReturnValue = string.Empty;

            var repositoriesInfo = new List<RepositoryInfo>();
            var scriptsReturnValue = new StringBuilder();
            var errors = new StringBuilder();

            foreach (var project in SelectedProjects)
            {
                var issues = new List<Issue>();
                try
                {
                    issues = _issueService.GetIssues(project.Id.ToString(CultureInfo.InvariantCulture),
                                                         IssueStatuses.TestPassed, null).ToList();
                }
                catch (RedmineException exception)
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_ErrorWhileFetchingFromRedmine, project.Name, exception.Message));
                }

                //if (!issues.Any())
                //{
                //    continue;
                //}

                var repository = _repositoryService.GetRepository(project.Name);
                var scriptReturnValue = _scriptService.CreatePackages(repository.Id);

                scriptsReturnValue.Append(scriptReturnValue);

                if (!scriptReturnValue.Contains(Resources.MainWindowViewModel_EverythingIsOk))
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_ErrorDuringRunningScript, project.Name));
                    ScriptsReturnValue = scriptsReturnValue.ToString();
                    continue;
                }

                RepositoryInfo repositoryInfo;
                try
                {
                    var gitRepository = new Repository(repository.Path);
                    repositoryInfo = new RepositoryInfo(repository, gitRepository.CurrentBranch.CurrentCommit.CommitDate,
                        gitRepository.CurrentBranch.CurrentCommit.Hash);
                }
                catch (DirectoryNotFoundException)
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_WrongRepositoryPathPleaseSeeYourConfig, project.Name));
                    continue;
                }

                repositoriesInfo.Add(repositoryInfo);

                try
                {
                    _documentBuilder.CreateAndSave(repositoryInfo, issues);
                }
                catch (ErrorWhileCreatingDocument errorWhileCreatingDocument)
                {
                    Messenger.Default.Send(errorWhileCreatingDocument.Message);
                    continue;
                }

                _issueService.CloseIssues(issues);
            }

            ScriptsReturnValue = scriptsReturnValue.ToString();

            if (errors.Length != 0)
            {
                Messenger.Default.Send(errors.ToString());
                return;
            }

            try
            {
                ScriptsReturnValue += _mailService.SendMail(repositoriesInfo);
            }
            catch (Exception)
            {
                Messenger.Default.Send(Resources.MainWindowViewModel_CouldNotSendEmail);
            }
        }
示例#20
0
 public void Checkout(string hash)
 {
     using (var repository = new GitSharp.Repository(FullPath)) {
         repository.CurrentBranch.Reset(hash, GitSharp.ResetBehavior.Hard);
     }
 }
示例#21
0
 public GitSharp.Commit GetLatestCommit()
 {
     using (var repository = new GitSharp.Repository(FullPath)) {
         return repository.Head.CurrentCommit;
     }
 }