Beispiel #1
0
        static void Main(string[] args)
        {
#if DEBUG
            OldLogger.AnnounceStartStopActions = true;
            OldLogger.Level = OldLogger.LevelValue.Verbose;
#endif

            string        currentBranch = GitOperations.GetCurrentBranchName();
            List <string> branches      = new List <string>(GitOperations.GetLocalBranches());
            branches.Remove(currentBranch);

            OldLogger.LogLine(@"Currently on " + currentBranch);
            OldLogger.LogLine(@"Select from the following:");
            for (int ii = 0; ii < Math.Min(9, branches.Count); ii++)
            {
                OldLogger.LogLine("\t" + (ii + 1) + " : " + branches[ii]);
            }
            OldLogger.LogLine("\tn : Make a new branch");
            OldLogger.LogLine("\tf : Follow an existing remote branch");
            string input = Console.ReadKey().KeyChar.ToString().Trim().ToLower();
            OldLogger.LogLine(string.Empty);
            if (string.IsNullOrEmpty(input) || (input.ToLower() == "q"))
            {
                return;
            }

            if (input.ToLower() == "n")
            {
                MakeNewBranch();
                return;
            }

            if (input.ToLower() == "f")
            {
                FollowExistingRemoteBranch();
                return;
            }

            if ((input == "-") || (input == "--"))
            {
                SwitchBranch("-");
                OldLogger.LogLine("Branch is now : " + GitOperations.GetCurrentBranchName());
                return;
            }

            int index = -1;
            if (!int.TryParse(input, out index))
            {
                OldLogger.LogLine(@"Not a valid number: " + input, OldLogger.LevelValue.Error);
                return;
            }

            if ((index <= 0) || (index > branches.Count))
            {
                OldLogger.LogLine(@"Invalid index: " + index, OldLogger.LevelValue.Error);
                return;
            }

            SwitchBranch(branches[index - 1]);
        }
Beispiel #2
0
        public void GetRepositoryUrl_Unix(string originUrl, string expectedUrl)
        {
            var repo = new TestRepository(workingDir: "/usr/src/a/b", commitSha: "1111111111111111111111111111111111111111",
                                          remotes: new[] { new TestRemote("origin", originUrl) });

            Assert.Equal(expectedUrl, GitOperations.GetRepositoryUrl(repo));
        }
Beispiel #3
0
        public void GetRepositoryUrl_Agnostic2(string originUrl, string expectedUrl)
        {
            var repo = new TestRepository(workingDir: s_root, commitSha: "1111111111111111111111111111111111111111",
                                          remotes: new[] { new TestRemote("origin", originUrl) });

            Assert.Equal(expectedUrl, GitOperations.GetRepositoryUrl(repo));
        }
Beispiel #4
0
        /// <summary>
        /// Get last 30 or less commits for current repository
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProjectRecentCommitsButton_Click(object sender, EventArgs e)
        {
            RepositoryCommitItem[] recentCommits = {};

            try
            {
                recentCommits = GitOperations.RecentCommits(RepositoryTextBox.Text, RepositoryListBox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to get commits\n{ex.Message}");
                Exceptions.Write(ex);
                return;
            }

            if (recentCommits.Length > 0)
            {
                var commitForm = new RepositoryRecentCommitsForm(recentCommits);
                try
                {
                    commitForm.ShowDialog();
                }
                finally
                {
                    commitForm.Dispose();
                }
            }
            else
            {
                MessageBox.Show("No commits found");
            }
        }
Beispiel #5
0
        public void BuildDirectoryTree()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: null,
                submodules: new[]
            {
                new TestSubmodule(null, "c/x", null, null),
                new TestSubmodule(null, "e", null, null),
                new TestSubmodule(null, "a", null, null),
                new TestSubmodule(null, "a/a/a/a/", null, null),
                new TestSubmodule(null, "c", null, null),
                new TestSubmodule(null, "a/z", null, null),
            });

            var root = GitOperations.BuildDirectoryTree(repo);

            string inspect(GitOperations.SourceControlDirectory node)
            => node.Name + (node.RepositoryFullPath != null ? $"!" : "") + "{" + string.Join(",", node.OrderedChildren.Select(inspect)) + "}";

            var expected = IsUnix ?
                           "{/{usr{src!{a!{a{a{a!{}}},z!{}},c!{x!{}},e!{}}}}}" :
                           "{C:{src!{a!{a{a{a!{}}},z!{}},c!{x!{}},e!{}}}}";

            Assert.Equal(expected, inspect(root));
        }
Beispiel #6
0
        public void GetSourceRoots_InvalidSubmoduleUrlOrPath()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http:///", "1111111111111111111111111111111111111111"),
                new TestSubmodule("2", "sub/\0*<>|:", "http://2.com", "2222222222222222222222222222222222222222"),
                new TestSubmodule("3", "sub/3", "http://3.com", "3333333333333333333333333333333333333333"),
            });

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            AssertEx.Equal(new[]
            {
                $@"'{s_root}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
                $@"'{s_root}{s}sub{s}3{s}' SourceControl='git' RevisionId='3333333333333333333333333333333333333333' NestedRoot='sub/3/' ContainingRoot='{s_root}{s}' RepositoryUrl='http://3.com/'",
            }, items.Select(InspectSourceRoot));

            AssertEx.Equal(new[]
            {
                string.Format(Resources.InvalidSubmoduleUrl_SourceLink, "1", "http:///"),
                string.Format(Resources.InvalidSubmodulePath_SourceLink, "2", "sub/\0*<>|:")
            }, warnings.Select(InspectDiagnostic));
        }
Beispiel #7
0
 private static void CreateBranch(string branchName, string basedOn)
 {
     if (!GitOperations.CreateBranch(branchName, basedOn, out ProcessHelper proc))
     {
         OldLogger.LogLine("Unable to create your branch", OldLogger.LevelValue.Error);
         OldLogger.LogLine(proc.AllOutput, OldLogger.LevelValue.Warning);
     }
 }
Beispiel #8
0
 private static void SwitchBranch(string newBranch)
 {
     if (!GitOperations.SwitchBranch(newBranch, out ProcessHelper proc))
     {
         OldLogger.LogLine("Unable to switch branches", OldLogger.LevelValue.Error);
         OldLogger.LogLine(proc.AllOutput, OldLogger.LevelValue.Warning);
     }
 }
Beispiel #9
0
        public void GetRepositoryUrl_NoRemotes()
        {
            var repo = new TestRepository(workingDir: s_root, commitSha: "1111111111111111111111111111111111111111");

            var warnings = new List <KeyValuePair <string, object[]> >();

            Assert.Null(GitOperations.GetRepositoryUrl(repo, (message, args) => warnings.Add(KVP(message, args))));
            AssertEx.Equal(new[] { Resources.RepositoryHasNoRemote }, warnings.Select(InspectDiagnostic));
        }
Beispiel #10
0
        private static void ApplyChanges(string masterBranch, string fromVersion, string toVersion)
        {
            string gitRootDir = GitOperations.GetRoot();

            Debug.Assert(Directory.Exists(gitRootDir));

            string currentDir = Directory.GetCurrentDirectory();

            Debug.Assert(IOHelper.IsSubdirectory(gitRootDir, currentDir));

            string[] directoriesWithDifferences = GitOperations.GetDifferentFiles(masterBranch)
                                                  .Where(path => path.ToLower().Contains("/" + fromVersion.ToLower() + "/"))
                                                  .Select(path => path.Substring(0, path.ToLower().IndexOf(fromVersion.ToLower())))
                                                  .Distinct()
                                                  .ToArray();
            Dictionary <string, string> patchPaths = new Dictionary <string, string>();

            OldLogger.Start("Generating Patches", OldLogger.LevelValue.Normal);
            foreach (string directoryWithDifference in directoriesWithDifferences)
            {
                string patchPath = Path.Combine(gitRootDir, fromVersion + "." + directoryWithDifference.Replace('\\', '-').Replace('/', '-').Trim(new char[] { '-' }) + ".patch");

                // git format-patch --relative origin/master . --stdout
                ProcessHelper proc = new ProcessHelper(@"C:\Program Files\Git\cmd\git.exe", $"format-patch --relative {masterBranch} . --stdout");
                proc.WorkingDirectory = Path.Combine(gitRootDir, directoryWithDifference, fromVersion);
                proc.Go();
                File.WriteAllText(patchPath, string.Join("\n", proc.RawOutput));
                patchPaths.Add(directoryWithDifference, patchPath);
            }
            OldLogger.Stop("Generating Patches", OldLogger.LevelValue.Normal);


            for (int ii = 0; ii < directoriesWithDifferences.Length; ii++)
            {
                string directoryWithDifference = directoriesWithDifferences[ii];
                string destinationDirectory    = Path.Combine(gitRootDir, directoryWithDifference, toVersion).Replace('\\', '/');
                string patchPath = patchPaths[directoryWithDifference];

                OldLogger.Start("Applying changes to " + destinationDirectory, OldLogger.LevelValue.Normal);
                // git apply --reject --directory=<destination-dir> --unsafe-paths <patch-path>
                ProcessHelper proc = new ProcessHelper("git.exe", $"apply --reject --directory={destinationDirectory} --unsafe-paths {patchPath}");
                proc.WorkingDirectory = gitRootDir;
                proc.Go();
                foreach (string line in proc.RawOutput)
                {
                    Console.WriteLine(line);
                }
                OldLogger.Stop("Applying changes to " + destinationDirectory, OldLogger.LevelValue.Normal);

                if (proc.RawOutput.Length > 0 && ii < directoriesWithDifferences.Length - 1)
                {
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                }
            }
        }
Beispiel #11
0
        public void GetSourceRoots_RepoWithoutCommits()
        {
            var repo = new TestRepository(workingDir: s_root, commitSha: null);

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            Assert.Empty(items);
            AssertEx.Equal(new[] { Resources.RepositoryWithoutCommit_SourceLink }, warnings.Select(InspectDiagnostic));
        }
Beispiel #12
0
        /// <summary>
        /// Fetch repository in repository TextBox
        /// </summary>
        /// <returns></returns>
        private async Task FetchSelectedRepository()
        {
            if (string.IsNullOrWhiteSpace(RepositoryTextBox.Text))
            {
                MessageBox.Show(@"Requires a repository");
                return;
            }

            WorkingPictureBox.Image = spinner;

            if (RepositoryListBox.DataSource != null)
            {
                _lastSelectedRepositoryName = RepositoryListBox.Text;
            }

            RepositoryListBox.DataSource = null;

            try
            {
                _repositoriesBindingList = new BindingList <Repository>(await GitOperations.DownLoadPublicRepositoriesAsync(RepositoryTextBox.Text));
            }
            catch (Exception ex)
            {
                WorkingPictureBox.Image = null;
                // a consideration is rate limit
                MessageBox.Show($@"Failed to get repositories {ex.Message}");
                return;
            }

            _repositoriesBindingSource.DataSource = _repositoriesBindingList;
            RepositoryListBox.DataSource          = _repositoriesBindingSource;

            if (_repositoriesBindingSource.Count > 0)
            {
                RepositoryListBox.SelectedIndex = 0;
            }

            BindControls();

            ControlHelpers.SetWaterMarkers(this);

            if (!string.IsNullOrWhiteSpace(_lastSelectedRepositoryName))
            {
                var index = RepositoryListBox.FindString(_lastSelectedRepositoryName);
                if (index >= 0)
                {
                    RepositoryListBox.SelectedIndex = index;
                }
            }

            ActiveControl           = RepositoryListBox;
            WorkingPictureBox.Image = null;
        }
Beispiel #13
0
        public void GetSourceRoots_GvfsWithModules()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                config: new Dictionary <string, object> {
                { "core.gvfs", true }
            },
                submodulesSupported: false);

            Assert.Throws <LibGit2SharpException>(() => GitOperations.GetSourceRoots(repo, null, fileExists: _ => true));
        }
        public async Task <IActionResult> CreateWebAPI([FromBody] WebAPI webApi)
        {
            if (webApi != null)
            {
                //var outputFolderPath = _hostingEnvironment.ContentRootPath + "\\" + webApi.projectName + localDateTime +"\\";
                var outputFolderPath = @"D:\work\poc\CodeGenOutput" + "\\" + webApi.projectName + localDateTime + "\\";
                while (!Directory.Exists(outputFolderPath))
                {
                    Directory.CreateDirectory(outputFolderPath);
                }
                if (webApi.saveToGit)
                {
                    gitOperations = new GitOperations(webApi.gitUsername, webApi.gitPassword, webApi.gitURL, outputFolderPath);
                    gitOperations.CloneRepo();
                    gitbranchName = gitbranchName + webApi.projectName;
                }

                var config = new CodeGenConfig()
                {
                    Messaging         = webApi.messaging,
                    UseCircuitbreaker = webApi.useCircuitBreaker,
                    PackageName       = webApi.projectName,
                    namespaceName     = webApi.namespaceName,
                    SwaggerFile       = webApi.swaggerPath,
                    outputFolderPath  = outputFolderPath
                };

                WebApiProjectCodeGen webApiProjectCodeGen = new WebApiProjectCodeGen();
                await webApiProjectCodeGen.GenerateProjectCode(config);

                if (webApi.saveToGit)
                {
                    if (!string.IsNullOrEmpty(webApi.gitUsername) && !string.IsNullOrEmpty(webApi.gitPassword) &&
                        !string.IsNullOrEmpty(webApi.gitURL))
                    {
                        var branches = gitOperations.ListGitBranches(gitbranchName);
                        if (!branches)
                        {
                            gitOperations.CreateBranch(gitbranchName, gitbranchName);
                            gitOperations.PushCommits(gitbranchName, gitbranchName);
                            return(Ok(new CreateResponse()
                            {
                                Result = "Project Created. Pushed to Git."
                            }));
                        }
                    }
                }
            }
            return(Ok(new CreateResponse()
            {
                Result = "Project Created. TODO: Download zip file."
            }));
        }
Beispiel #15
0
        private static void MakeNewBranch()
        {
            string suggestedPrefix = "u/" + Environment.GetEnvironmentVariable("USERNAME") + "/";

            OldLogger.Log("\r\nPrefix? [" + suggestedPrefix + "] : ");
            string prefix = Console.ReadLine().Trim().ToLower().Replace('_', '-').Replace(' ', '-');

            if (string.IsNullOrEmpty(prefix))
            {
                prefix = suggestedPrefix;
            }
            OldLogger.Log("Short name : ");
            string shortName = Console.ReadLine().Trim().ToLower().Replace('_', '-').Replace(' ', '-');

            if (string.IsNullOrEmpty(shortName))
            {
                OldLogger.LogLine("Short name must be provided!", OldLogger.LevelValue.Error);
                return;
            }
            string branchName = string.Join("/", string.Join("/", new string[] { prefix, shortName }).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));

            string suggestedBasedOn = GitOperations.GetBranchBase(GitOperations.GetCurrentBranchName());

            if (string.IsNullOrEmpty(suggestedBasedOn))
            {
                suggestedBasedOn = GetDefaultBranch();
            }
            OldLogger.Log("Based on what branch? [" + suggestedBasedOn + "] : ");
            string basedOn = Console.ReadLine().Trim();

            if (string.IsNullOrEmpty(basedOn))
            {
                basedOn = suggestedBasedOn;
            }

            string remoteBranchName = "origin/" + branchName;

            OldLogger.LogLine("Confirming new branch called " + branchName + " based on " + basedOn);
            OldLogger.LogLine("This will also be tracking " + remoteBranchName);
            OldLogger.Log("That look ok? [y] ");
            string prompt = Console.ReadKey().KeyChar.ToString().Trim().ToLower();

            OldLogger.LogLine(string.Empty);
            if (string.IsNullOrEmpty(prompt))
            {
                prompt = "y";
            }
            if (prompt == "y")
            {
                CreateBranch(branchName, basedOn);
            }
        }
Beispiel #16
0
        private void ValidateGetRepositoryUrl(string workingDir, string actualUrl, string expectedUrl)
        {
            var testRemote = new TestRemote("origin", actualUrl);

            var repo = new TestRepository(workingDir, commitSha: "1111111111111111111111111111111111111111",
                                          remotes: new[] { testRemote });

            var expectedWarnings = (expectedUrl != null) ?
                                   Array.Empty <string>() :
                                   new[] { string.Format(Resources.InvalidRepositoryRemoteUrl, testRemote.Name, testRemote.Url) };

            var warnings = new List <KeyValuePair <string, object[]> >();

            Assert.Equal(expectedUrl, GitOperations.GetRepositoryUrl(repo, (message, args) => warnings.Add(KVP(message, args))));
            AssertEx.Equal(expectedWarnings, warnings.Select(InspectDiagnostic));
        }
Beispiel #17
0
        private static void MergeBranch(string localBranch, string mergeSource)
        {
            if (!GitOperations.IsBranchBehind(localBranch, mergeSource))
            {
                OldLogger.LogLine(localBranch + " is up to date with " + mergeSource);
                return;
            }

            if (!GitOperations.SwitchBranch(localBranch, out ProcessHelper failureProc))
            {
                OldLogger.LogLine("Unable to switch branches", OldLogger.LevelValue.Warning);
                OldLogger.LogLine(failureProc.AllOutput, OldLogger.LevelValue.Normal);
                return;
            }

            GitOperations.MergeFromBranch(mergeSource);
        }
Beispiel #18
0
        public void GetSourceRoots_GvfsWithoutModules()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                config: new Dictionary <string, object> {
                { "core.gvfs", true }
            },
                submodulesSupported: false);

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: _ => false);

            AssertEx.Equal(new[]
            {
                $@"'{s_root}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
            }, items.Select(InspectSourceRoot));
        }
Beispiel #19
0
        public void GetUntrackedFiles_ProjectInMainRepoIncludesFilesInSubmodules()
        {
            string gitRoot = s_root.Replace('\\', '/');

            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http://1.com", "1111111111111111111111111111111111111111"),
                new TestSubmodule("2", "sub/2", "http://2.com", "2222222222222222222222222222222222222222")
            },
                ignoredPaths: new[] { gitRoot + @"/c.cs", gitRoot + @"/p/d.cs", gitRoot + @"/sub/1/x.cs" });

            var subRoot1 = Path.Combine(s_root, "sub", "1");
            var subRoot2 = Path.Combine(s_root, "sub", "2");

            var subRepos = new Dictionary <string, TestRepository>()
            {
                { subRoot1, new TestRepository(subRoot1, commitSha: null, ignoredPaths: new[] { gitRoot + @"/sub/1/obj/a.cs" }) },
                { subRoot2, new TestRepository(subRoot2, commitSha: null, ignoredPaths: new[] { gitRoot + @"/sub/2/obj/b.cs" }) },
            };

            var actual = GitOperations.GetUntrackedFiles(repo,
                                                         new[]
            {
                new MockItem(@"c.cs"),                             // not ignored
                new MockItem(@"..\sub\1\x.cs"),                    // ignored in the main repository, but not in the submodule (which has a priority)
                new MockItem(@"../sub/2/obj/b.cs"),                // ignored in submodule #2
                new MockItem(@"d.cs"),                             // not ignored
                new MockItem(@"..\..\w.cs"),                       // outside of repo
                new MockItem(IsUnix ? "/d/w.cs" : @"D:\w.cs"),     // outside of repo
            },
                                                         projectDirectory: Path.Combine(s_root, "p"),
                                                         root => subRepos[root]);

            AssertEx.Equal(new[]
            {
                MockItem.AdjustSeparators("../sub/2/obj/b.cs"),
                MockItem.AdjustSeparators("d.cs"),
                MockItem.AdjustSeparators(@"..\..\w.cs"),
                MockItem.AdjustSeparators(IsUnix ? "/d/w.cs" : @"D:\w.cs")
            }, actual.Select(item => item.ItemSpec));
        }
Beispiel #20
0
        /// <summary>
        /// Temp code for testing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FoldersForSelectedButton_Click(object sender, EventArgs e)
        {
            if (RepositoryListBox.DataSource == null || string.IsNullOrWhiteSpace(RepositoryListBox.Text))
            {
                return;
            }

            var directories       = GitOperations.Directories(RepositoryTextBox.Text, RepositoryListBox.Text);
            var directoryNameList = directories.Where(item => item.type == "dir").Select(item => item.name).ToList();

            var repoDirectoryForm = new RepositoryDirectoryForm(directoryNameList);

            try
            {
                repoDirectoryForm.ShowDialog();
            }
            finally
            {
                repoDirectoryForm.Dispose();
            }
        }
Beispiel #21
0
        /// <summary>
        /// Provides logic to move menu items up/down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateDownLoadBatchFileButton_Click(object sender, EventArgs e)
        {
            if (RepositoryListBox.DataSource == null || string.IsNullOrWhiteSpace(RepositoryListBox.Text))
            {
                return;
            }

            var directories   = GitOperations.Directories(RepositoryTextBox.Text, RepositoryListBox.Text);
            var directoryList = directories.Where(item => item.type == "dir").Select(item => item.name).ToList();

            var f = new CreateDownloadBatchForm(directoryList, HtmlUrlTextBox.Text);

            try
            {
                f.ShowDialog();
            }
            finally
            {
                f.Dispose();
            }
        }
Beispiel #22
0
        private static bool UpdateBranch(string localBranch, string remoteBranch = null)
        {
            remoteBranch = remoteBranch ?? ("origin/" + localBranch);

            if (!GitOperations.IsBranchBehind(localBranch, remoteBranch))
            {
                OldLogger.LogLine($"{localBranch} is up to date with {remoteBranch}");
                return(false);
            }

            if (!GitOperations.SwitchBranch(localBranch, out ProcessHelper failureProc))
            {
                OldLogger.LogLine("Unable to switch branches", OldLogger.LevelValue.Warning);
                OldLogger.LogLine(failureProc.AllOutput, OldLogger.LevelValue.Normal);
                return(false);
            }

            GitOperations.PullCurrentBranch();

            return(true);
        }
Beispiel #23
0
        public void GetContainingRepository_Unix(string path, string expectedDirectory)
        {
            var actual = GitOperations.GetContainingRepository(path,
                                                               new GitOperations.SourceControlDirectory("", null,
                                                                                                        new List <GitOperations.SourceControlDirectory>
            {
                new GitOperations.SourceControlDirectory("/", null, new List <GitOperations.SourceControlDirectory>
                {
                    new GitOperations.SourceControlDirectory("src", "/src", new List <GitOperations.SourceControlDirectory>
                    {
                        new GitOperations.SourceControlDirectory("a", "/src/a"),
                        new GitOperations.SourceControlDirectory("c", "/src/c", new List <GitOperations.SourceControlDirectory>
                        {
                            new GitOperations.SourceControlDirectory("x", "/src/c/x"),
                        }),
                        new GitOperations.SourceControlDirectory("e", "/src/e"),
                    }),
                })
            }));

            Assert.Equal(expectedDirectory, actual?.RepositoryFullPath);
        }
Beispiel #24
0
        public void GetContainingRepository_Windows(string path, string expectedDirectory)
        {
            var actual = GitOperations.GetContainingRepository(path,
                                                               new GitOperations.SourceControlDirectory("", null,
                                                                                                        new List <GitOperations.SourceControlDirectory>
            {
                new GitOperations.SourceControlDirectory("C:", null, new List <GitOperations.SourceControlDirectory>
                {
                    new GitOperations.SourceControlDirectory("src", @"C:\src", new List <GitOperations.SourceControlDirectory>
                    {
                        new GitOperations.SourceControlDirectory("a", @"C:\src\a"),
                        new GitOperations.SourceControlDirectory("c", @"C:\src\c", new List <GitOperations.SourceControlDirectory>
                        {
                            new GitOperations.SourceControlDirectory("x", @"C:\src\c\x")
                        }),
                        new GitOperations.SourceControlDirectory("e", @"C:\src\e")
                    }),
                })
            }));

            Assert.Equal(expectedDirectory, actual?.RepositoryFullPath);
        }
Beispiel #25
0
        public void GetSourceRoots_GvfsBadOptionType()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                config: new Dictionary <string, object> {
                { "core.gvfs", 1 }
            },
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http://1.com/", "1111111111111111111111111111111111111111"),
            });

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            AssertEx.Equal(new[]
            {
                $@"'{s_root}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
                $@"'{s_root}{s}sub{s}1{s}' SourceControl='git' RevisionId='1111111111111111111111111111111111111111' NestedRoot='sub/1/' ContainingRoot='{s_root}{s}' RepositoryUrl='http://1.com/'",
            }, items.Select(InspectSourceRoot));
        }
Beispiel #26
0
        public void GetSourceRoots_RepoWithCommitsWithSubmodules()
        {
            var repo = new TestRepository(
                workingDir: s_root,
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "http://1.com", workDirCommitSha: null),
                new TestSubmodule("1", "sub/2", "http://2.com", "2222222222222222222222222222222222222222")
            });

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            AssertEx.Equal(new[]
            {
                $@"'{s_root}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
                $@"'{s_root}{s}sub{s}2{s}' SourceControl='git' RevisionId='2222222222222222222222222222222222222222' NestedRoot='sub/2/' ContainingRoot='{s_root}{s}' RepositoryUrl='http://2.com/'",
            }, items.Select(InspectSourceRoot));

            AssertEx.Equal(new[] { string.Format(Resources.SubmoduleWithoutCommit_SourceLink, "1") }, warnings.Select(InspectDiagnostic));
        }
Beispiel #27
0
        public void GetSourceRoots_RelativeSubmodulePaths_Windows_UnicodeAndEscapes()
        {
            var repo = new TestRepository(
                workingDir: @"C:\%25@噸",
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("%25ሴ", "sub/%25ሴ", "./a/b", "1111111111111111111111111111111111111111"),
                new TestSubmodule("%25ለ", "sub/%25ለ", "../a", "2222222222222222222222222222222222222222"),
            });

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            AssertEx.Equal(new[]
            {
                $@"'C:\%25@噸\' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
                $@"'C:\%25@噸\sub\%25ሴ\' SourceControl='git' RevisionId='1111111111111111111111111111111111111111' NestedRoot='sub/%25ሴ/' ContainingRoot='C:\%25@噸\' ScmRepositoryUrl='file:///C:/%25@噸/a/b'",
                $@"'C:\%25@噸\sub\%25ለ\' SourceControl='git' RevisionId='2222222222222222222222222222222222222222' NestedRoot='sub/%25ለ/' ContainingRoot='C:\%25@噸\' ScmRepositoryUrl='file:///C:/a'",
            }, items.Select(InspectSourceRoot));

            Assert.Empty(warnings);
        }
Beispiel #28
0
        public void GetSourceRoots_RelativeSubmodulePaths_Unix()
        {
            var repo = new TestRepository(
                workingDir: @"/src",
                commitSha: "0000000000000000000000000000000000000000",
                submodules: new[]
            {
                new TestSubmodule("1", "sub/1", "./a/b", "1111111111111111111111111111111111111111"),
                new TestSubmodule("2", "sub/2", "../a", "2222222222222222222222222222222222222222"),
            });

            var warnings = new List <KeyValuePair <string, object[]> >();
            var items    = GitOperations.GetSourceRoots(repo, (message, args) => warnings.Add(KVP(message, args)), fileExists: null);

            AssertEx.Equal(new[]
            {
                $@"'/src/' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'",
                $@"'/src/sub/1/' SourceControl='git' RevisionId='1111111111111111111111111111111111111111' NestedRoot='sub/1/' ContainingRoot='/src/' RepositoryUrl='file:///src/a/b'",
                $@"'/src/sub/2/' SourceControl='git' RevisionId='2222222222222222222222222222222222222222' NestedRoot='sub/2/' ContainingRoot='/src/' RepositoryUrl='file:///a'",
            }, items.Select(InspectSourceRoot));

            Assert.Empty(warnings);
        }
Beispiel #29
0
        public void GetRepositoryUrl_NoRemotes()
        {
            var repo = new TestRepository(workingDir: s_root, commitSha: "1111111111111111111111111111111111111111");

            Assert.Null(GitOperations.GetRepositoryUrl(repo));
        }
Beispiel #30
0
        public void GetRevisionId_RepoWithCommit()
        {
            var repo = new TestRepository(workingDir: "", commitSha: "8398cdcd9043724b9bef1efda8a703dfaa336c0f");

            Assert.Equal("8398cdcd9043724b9bef1efda8a703dfaa336c0f", GitOperations.GetRevisionId(repo));
        }