예제 #1
0
        public void Commit(string author, string comment, params LogPropertyInfo[] properties)
        {
            if (this.transactionName != null)
            {
                var diffCommand = new GitCommand(this.BasePath, "diff")
                {
                    "HEAD",
                    new GitCommandItem("stat"),
                    new GitCommandItem("binary")
                };
                var output = diffCommand.ReadLine();
                FileUtility.Prepare(this.transactionPatchPath);
                File.WriteAllText(this.transactionPatchPath, output);
                this.transactionMessageList.Add(comment);
                this.transactionPropertyList.AddRange(properties);
                return;
            }

            try
            {
                var statusCommand = new GitCommand(this.BasePath, "status")
                {
                    new GitCommandItem('s')
                };
                var items = statusCommand.ReadLines(true);
                if (items.Length != 0)
                {
                    var authorValue = new GitAuthor(author);
                    GitConfig.SetValue(this.BasePath, "user.email", authorValue.Email == string.Empty ? "<>" : authorValue.Email);
                    GitConfig.SetValue(this.BasePath, "user.name", authorValue.Name);

                    var commitCommand = new GitCommitCommand(this.BasePath, author, comment);
                    var result        = commitCommand.Run(this.logService);
                    this.logService?.Debug(result);
                    var log = GitLogInfo.GetLatestLog(this.BasePath);
                    this.repositoryInfo.Revision         = log.CommitID;
                    this.repositoryInfo.ModificationInfo = new SignatureDate(author, log.CommitDate);

                    this.SetNotes(properties);
                    //this.isModified = true;
                    //this.Pull();
                    //this.Push();
                    //this.PushNotes();
                }
                else
                {
                    this.logService?.Debug("repository no changes. \"{0}\"", this.BasePath);
                }
            }
            catch (Exception e)
            {
                this.logService?.Warn(e);
                throw;
            }
        }
예제 #2
0
        public IRepository CreateInstance(RepositorySettings settings)
        {
            var remoteUri      = new Uri(settings.RemotePath);
            var baseUri        = new Uri(settings.BasePath);
            var originUri      = UriUtility.MakeRelativeOfDirectory(baseUri, remoteUri);
            var repositoryName = settings.RepositoryName == string.Empty ? "master" : settings.RepositoryName;

            if (Directory.Exists(settings.BasePath) == false)
            {
                var cloneCommand = new GitCommand(null, "clone")
                {
                    (GitPath)remoteUri,
                    new GitCommandItem('b'),
                    repositoryName,
                    (GitPath)settings.BasePath,
                    new GitCommandItem("single-branch")
                };
                cloneCommand.Run();

                var fetchCommand = new GitCommand(settings.BasePath, "fetch")
                {
                    "origin",
                    "refs/notes/commits:refs/notes/commits",
                };
                fetchCommand.Run();

                var id = this.GetID(settings.RemotePath, repositoryName);
                this.SetID(settings.BasePath, repositoryName, id);
                GitConfig.SetValue(settings.BasePath, "remote.origin.url", originUri);
                var repositoryInfo = this.GetRepositoryInfo(settings.RemotePath, repositoryName);
                return(new GitRepository(this, settings, repositoryInfo));
            }
            else
            {
                var repositoryInfo = this.GetRepositoryInfo(settings.BasePath, repositoryName);
                return(new GitRepository(this, settings, repositoryInfo));
            }
        }
예제 #3
0
 private string GetDescription(string repositoryPath, string repositoryName)
 {
     return(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.description"));
 }
예제 #4
0
 private bool HasDescription(string repositoryPath, string repositoryName)
 {
     return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.description"));
 }
예제 #5
0
 private void SetDescription(string repositoryPath, string repositoryName, string description)
 {
     GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.description", $"{description}");
 }
예제 #6
0
 private SignatureDate GetCreationInfo(string repositoryPath, string repositoryName)
 {
     return(SignatureDate.Parse(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.createdDateTime"), CultureInfo.GetCultureInfo("en-US")));
 }
예제 #7
0
 private bool HasCreationInfo(string repositoryPath, string repositoryName)
 {
     return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.createdDateTime"));
 }
예제 #8
0
 private void SetCreationInfo(string repositoryPath, string repositoryName, SignatureDate signatureDate)
 {
     GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.createdDateTime", $"{signatureDate.ToString(CultureInfo.GetCultureInfo("en-US"))}");
 }
예제 #9
0
 private Guid GetID(string repositoryPath, string repositoryName)
 {
     return(Guid.Parse(GitConfig.GetValue(repositoryPath, $"branch.{repositoryName}.id")));
 }
예제 #10
0
 private bool HasID(string repositoryPath, string repositoryName)
 {
     return(GitConfig.HasValue(repositoryPath, $"branch.{repositoryName}.id"));
 }
예제 #11
0
 private void UnsetID(string repositoryPath, string repositoryName)
 {
     GitConfig.UnsetValue(repositoryPath, $"branch.{repositoryName}.id");
 }
예제 #12
0
 private void SetID(string repositoryPath, string repositoryName, Guid guid)
 {
     GitConfig.SetValue(repositoryPath, $"branch.{repositoryName}.id", $"{guid}");
 }
예제 #13
0
        public void InitializeRepository(string basePath, string repositoryPath, params LogPropertyInfo[] properties)
        {
            var cloneCommand = new GitCommand(null, "clone")
            {
                (GitPath)repositoryPath,
                (GitPath)basePath,
            };

            if (cloneCommand.TryRun() == true)
            {
                var fetchCommand = new GitCommand(basePath, "fetch")
                {
                    "origin",
                    "refs/notes/commits:refs/notes/commits",
                };
                fetchCommand.Run();
                GitConfig.SetValue(basePath, "receive.denyCurrentBranch", "ignore");
                return;
            }

            var initCommand = new GitCommand(null, "init")
            {
                (GitPath)basePath
            };

            initCommand.Run();

            var configCommand = new GitCommand(basePath, "config")
            {
                "receive.denyCurrentBranch",
                "ignore"
            };

            configCommand.Run();

            DirectoryUtility.Copy(repositoryPath, basePath);
            foreach (var item in GetEmptyDirectories(basePath))
            {
                File.WriteAllText(Path.Combine(item, KeepExtension), string.Empty);
            }

            var query = from item in DirectoryUtility.GetAllFiles(basePath, "*", true)
                        select(GitPath) PathUtility.GetFullPath(item);
            var itemList = query.ToList();

            var addCommand = new GitAddCommand(basePath, query.ToArray());

            addCommand.Run();

            var commitCommand = new GitCommitCommand(basePath, Environment.UserName, "first commit");

            commitCommand.Run();

            var props           = properties.Select(item => (GitPropertyValue)item).ToArray();
            var propText        = propertySerializer.Serialize(props);
            var addNotesCommand = new GitCommand(basePath, "notes")
            {
                "add",
                GitCommandItem.FromMessage(propText)
            };

            addNotesCommand.Run();

            this.SetID(basePath, "master", Guid.NewGuid());
        }