Exemple #1
0
        public void GetSuperprojectCurrentCheckout()
        {
            // Create super and sub repo
            using (CommonTestUtils.GitModuleTestHelper moduleTestHelperSuper = new CommonTestUtils.GitModuleTestHelper("super repo"),
                   moduleTestHelperSub = new CommonTestUtils.GitModuleTestHelper("sub repo"))
            {
                // Inital commit in super project
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Initial commit""");

                // Submodules require at least one commit
                moduleTestHelperSub.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Empty commit""");

                // Add submodule
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(moduleTestHelperSub.Module.WorkingDir.ToPosixPath(), "sub repo", null, true));
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");
                GitModule moduleSub = new GitModule(Path.Combine(moduleTestHelperSuper.Module.WorkingDir, "sub repo").ToPosixPath());

                // Init submodule
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"submodule update --init --recursive");

                // Commit in submodule
                moduleSub.GitExecutable.GetOutput(@"commit --allow-empty -am ""First commit""");
                string commitRef = moduleSub.GitExecutable.GetOutput("show HEAD").Split('\n')[0].Split(' ')[1];

                // Update ref in superproject
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"add ""sub repo""");
                moduleTestHelperSuper.Module.GitExecutable.GetOutput(@"commit -am ""Update submodule ref""");

                // Assert
                (char code, ObjectId commitId) = moduleSub.GetSuperprojectCurrentCheckout();
                Assert.AreEqual(32, code);
                Assert.AreEqual(commitRef, commitId.ToString());
            }
        }
        /// <summary>
        /// Adds 'subModuleHelper' as a submodule of the current subModuleHelper.
        /// </summary>
        /// <param name="subModuleHelper">GitModuleTestHelper to add as a submodule of this.</param>
        /// <param name="path">Relative submodule path.</param>
        public void AddSubmodule(GitModuleTestHelper subModuleHelper, string path)
        {
            // Submodules require at least one commit
            subModuleHelper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Initial empty commit""");

            Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(subModuleHelper.Module.WorkingDir.ToPosixPath(), path, null, true), throwOnErrorOutput: false);
            Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");
        }
        /// <summary>
        /// Adds 'helper' as a submodule of the current helper.
        /// </summary>
        /// <param name="helper">GitModuleTestHelper to add as a submodule of this.</param>
        /// <param name="path">Relative submodule path.</param>
        /// <returns>Module of added submodule</returns>
        public VsrModule AddSubmodule(GitModuleTestHelper helper, string path)
        {
            // Submodules require at least one commit
            helper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Empty commit""");

            Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(helper.Module.WorkingDir.ToPosixPath(), path, null, true));
            Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");

            return(new VsrModule(Path.Combine(Module.WorkingDir, path).ToPosixPath()));
        }
Exemple #4
0
        public void GetSubmodulesLocalPaths()
        {
            var moduleTestHelpers = new List <CommonTestUtils.GitModuleTestHelper>();

            try
            {
                const int numModules = 4;

                for (int i = 0; i < numModules; ++i)
                {
                    moduleTestHelpers.Add(new CommonTestUtils.GitModuleTestHelper($"repo{i}"));
                }

                foreach (var helper in moduleTestHelpers)
                {
                    // Submodules require at least one commit
                    helper.Module.GitExecutable.GetOutput(@"commit --allow-empty -m ""Initial commit""");
                }

                for (int i = numModules - 1; i > 0; --i)
                {
                    var parent = moduleTestHelpers[i - 1];
                    var child  = moduleTestHelpers[i];

                    // Add child as submodule of parent
                    parent.Module.GitExecutable.GetOutput(GitCommandHelpers.AddSubmoduleCmd(child.Module.WorkingDir.ToPosixPath(), $"repo{i}", null, true));
                    parent.Module.GitExecutable.GetOutput(@"commit -am ""Add submodule""");
                }

                // Init all modules of root
                var root = moduleTestHelpers[0];
                root.Module.GitExecutable.GetOutput(@"submodule update --init --recursive");

                var paths = root.Module.GetSubmodulesLocalPaths(recursive: true);
                Assert.AreEqual(3, paths.Count);
                Assert.AreEqual(new string[] { "repo1", "repo1/repo2", "repo1/repo2/repo3" }, paths);

                paths = root.Module.GetSubmodulesLocalPaths(recursive: false);
                Assert.AreEqual(1, paths.Count);
                Assert.AreEqual(new string[] { "repo1" }, paths);
            }
            finally
            {
                foreach (var helper in moduleTestHelpers)
                {
                    helper.Dispose();
                }
            }
        }
Exemple #5
0
        private void AddClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Directory.Text) || string.IsNullOrEmpty(LocalPath.Text))
            {
                MessageBox.Show(this, _remoteAndLocalPathRequired.Text, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (WaitCursorScope.Enter())
            {
                var command = GitCommandHelpers.AddSubmoduleCmd(Directory.Text, LocalPath.Text, Branch.Text, chkForce.Checked);
                FormProcess.ShowDialog(this, process: null, arguments: command, Module.WorkingDir, input: null, useDialogSettings: true);
                Close();
            }
        }
Exemple #6
0
        private void AddClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Directory.Text) || string.IsNullOrEmpty(LocalPath.Text))
            {
                MessageBox.Show(this, _remoteAndLocalPathRequired.Text, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (WaitCursorScope.Enter())
            {
                FormProcess.ShowDialog(this, GitCommandHelpers.AddSubmoduleCmd(Directory.Text, LocalPath.Text, Branch.Text, chkForce.Checked));

                Close();
            }
        }
        private void AddClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Directory.Text) || string.IsNullOrEmpty(LocalPath.Text))
            {
                MessageBox.Show(this, _remoteAndLocalPathRequired.Text, Text);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            var addSubmoduleCmd = GitCommandHelpers.AddSubmoduleCmd(Directory.Text, LocalPath.Text, Branch.Text);

            new FormProcess(addSubmoduleCmd).ShowDialog(this);

            Close();
            Cursor.Current = Cursors.Default;
        }
        public void AddSubmoduleCmd()
        {
            Assert.AreEqual(
                "submodule add -b \"branch\" \"remotepath\" \"localpath\"",
                GitCommandHelpers.AddSubmoduleCmd("remotepath", "localpath", "branch", force: false).Arguments);

            Assert.AreEqual(
                "submodule add \"remotepath\" \"localpath\"",
                GitCommandHelpers.AddSubmoduleCmd("remotepath", "localpath", branch: null, force: false).Arguments);

            Assert.AreEqual(
                "submodule add -f -b \"branch\" \"remotepath\" \"localpath\"",
                GitCommandHelpers.AddSubmoduleCmd("remotepath", "localpath", "branch", force: true).Arguments);

            Assert.AreEqual(
                "submodule add -f -b \"branch\" \"remote/path\" \"local/path\"",
                GitCommandHelpers.AddSubmoduleCmd("remote\\path", "local\\path", "branch", force: true).Arguments);
        }