Ejemplo n.º 1
0
        public void BlameDiffWithNotCommitedItem(bool toVcs, bool commit)
        {
            string added = LocalPath.Combine("init");

            AddFile("init", "init", toVcs, commit);

            Assert.AreEqual(string.Empty, Repo.GetBaseText(added));
            var revisions = Repo.GetAnnotations(added, null).Select(a => a.Revision);

            foreach (var rev in revisions)
            {
                Assert.AreEqual(GettextCatalog.GetString("working copy"), rev);
            }
        }
        protected override void CheckLog(Repository repo)
        {
            var revs = repo.GetHistory(LocalPath.Combine("."), null);

            for (int i = 0; i < revs.Length - 1; ++i)
            {
                var svnRev = (SvnRevision)revs [i];
                Assert.AreEqual(revs.Length - 1 - i, svnRev.Rev);
                Assert.AreEqual(string.Format("Commit #{0}", revs.Length - 2 - i), svnRev.Message);
            }

            Assert.AreEqual(0, ((SvnRevision)revs [revs.Length - 1]).Rev);
            Assert.AreEqual(null, revs [revs.Length - 1].Message);
        }
Ejemplo n.º 3
0
        public async Task TestGitStagedNewFileStatus(bool testUnstagedRemove)
        {
            var repo2    = (GitRepository)Repo;
            var testFile = "file1";
            var testPath = LocalPath.Combine("file1");

            await AddFileAsync("file", null, true, true);
            await AddFileAsync(testFile, "test 1\n", false, false);

            // new file added but not staged
            var status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsFalse(status.HasLocalChanges);
            Assert.AreEqual(VersionStatus.Unversioned, status.Status);

            // stage added file
            LibGit2Sharp.Commands.Stage(repo2.RootRepository, testPath);
            status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsTrue(status.HasLocalChanges);
            Assert.AreEqual(VersionStatus.ScheduledAdd | VersionStatus.Versioned, status.Status);

            // modify the file without staging
            File.AppendAllText(testPath, "test 2\n");
            status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsTrue(status.Equals(await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache)));

            // remove the staged file
            File.Delete(testPath);
            // TODO: at this point the file still exists in the index, but should be detected as Unversioned
            if (testUnstagedRemove)
            {
                status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

                Assert.IsFalse(status.HasLocalChanges);
                Assert.AreEqual(VersionStatus.Unversioned, status.Status);
            }

            // stage removed file
            LibGit2Sharp.Commands.Stage(repo2.RootRepository, testPath);
            status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsFalse(status.HasLocalChanges);
            Assert.AreEqual(VersionStatus.Unversioned, status.Status);
        }
Ejemplo n.º 4
0
        // Tests bug #23274
        public void DeleteWithStagedChanges()
        {
            string added = LocalPath.Combine("testfile");

            AddFile("testfile", "test", true, true);

            // Test with VCS Remove.
            File.WriteAllText("testfile", "t");
            Repo.Add(added, false, new ProgressMonitor());
            Repo.DeleteFile(added, false, new ProgressMonitor(), true);
            Assert.AreEqual(VersionStatus.Versioned | VersionStatus.ScheduledDelete, Repo.GetVersionInfo(added, VersionInfoQueryFlags.IgnoreCache).Status);

            // Reset state.
            Repo.Revert(added, false, new ProgressMonitor());

            // Test with Project Remove.
            File.WriteAllText("testfile", "t");
            Repo.Add(added, false, new ProgressMonitor());
            Repo.DeleteFile(added, false, new ProgressMonitor(), false);
            Assert.AreEqual(VersionStatus.Versioned | VersionStatus.ScheduledDelete, Repo.GetVersionInfo(added, VersionInfoQueryFlags.IgnoreCache).Status);
        }
Ejemplo n.º 5
0
        public async Task BlameDiffWithNotCommitedItem(bool toVcs, bool commit)
        {
            string added = LocalPath.Combine("init");

            var contents = string.Join(Environment.NewLine, Enumerable.Repeat("string", 10));

            await AddFileAsync("init", contents, toVcs, commit);

            var expectedBaseText = commit ? contents : string.Empty;

            Assert.AreEqual(expectedBaseText, await Repo.GetBaseTextAsync(added));
            var revisions = (await Repo.GetAnnotationsAsync(added, null)).Select(a => a.Revision);

            string expectedRevision = commit
                                ? "Commit #0\n"
                                : GettextCatalog.GetString("working copy");

            foreach (var rev in revisions)
            {
                Assert.AreEqual(expectedRevision, rev.Message);
            }
        }
Ejemplo n.º 6
0
        public override void ExecuteCmdlet()
        {
            CloudFile fileToBeDownloaded;

            string[] path = NamingUtil.ValidatePath(this.Path, true);
            switch (this.ParameterSetName)
            {
            case LocalConstants.FileParameterSetName:
                fileToBeDownloaded = this.File;
                break;

            case LocalConstants.ShareNameParameterSetName:
                var share = this.BuildFileShareObjectFromName(this.ShareName);
                fileToBeDownloaded = share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.ShareParameterSetName:
                fileToBeDownloaded = this.Share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.DirectoryParameterSetName:
                fileToBeDownloaded = this.Directory.GetFileReferenceByPath(path);
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            string resolvedDestination = this.GetUnresolvedProviderPathFromPSPath(
                string.IsNullOrWhiteSpace(this.Destination) ? "." : this.Destination);

            FileMode mode = this.Force ? FileMode.Create : FileMode.CreateNew;
            string   targetFile;

            if (LocalDirectory.Exists(resolvedDestination))
            {
                // If the destination pointed to an existing directory, we
                // would download the file into the folder with the same name
                // on cloud.
                targetFile = LocalPath.Combine(resolvedDestination, fileToBeDownloaded.GetBaseName());
            }
            else
            {
                // Otherwise we treat the destination as a file no matter if
                // there's one existing or not. The overwrite behavior is configured
                // by FileMode.
                targetFile = resolvedDestination;
            }

            if (ShouldProcess(targetFile, "Download"))
            {
                this.RunTask(async taskId =>
                {
                    await
                    fileToBeDownloaded.FetchAttributesAsync(null, this.RequestOptions, OperationContext,
                                                            CmdletCancellationToken);

                    var progressRecord = new ProgressRecord(
                        this.OutputStream.GetProgressId(taskId),
                        string.Format(CultureInfo.CurrentCulture, Resources.ReceiveAzureFileActivity,
                                      fileToBeDownloaded.GetFullPath(), targetFile),
                        Resources.PrepareDownloadingFile);

                    await DataMovementTransferHelper.DoTransfer(() =>
                    {
                        return(this.TransferManager.DownloadAsync(
                                   fileToBeDownloaded,
                                   targetFile,
                                   new DownloadOptions
                        {
                            DisableContentMD5Validation = !this.CheckMd5
                        },
                                   this.GetTransferContext(progressRecord, fileToBeDownloaded.Properties.Length),
                                   CmdletCancellationToken));
                    },
                                                                progressRecord,
                                                                this.OutputStream);

                    if (this.PassThru)
                    {
                        this.OutputStream.WriteObject(taskId, fileToBeDownloaded);
                    }
                });
            }
        }
        public override void ExecuteCmdlet()
        {
            CloudFile fileToBeDownloaded;

            string[] path = NamingUtil.ValidatePath(this.Path, true);
            switch (this.ParameterSetName)
            {
            case LocalConstants.FileParameterSetName:
                fileToBeDownloaded = this.File;
                break;

            case LocalConstants.ShareNameParameterSetName:
                var share = this.BuildFileShareObjectFromName(this.ShareName);
                fileToBeDownloaded = share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.ShareParameterSetName:
                fileToBeDownloaded = this.Share.GetRootDirectoryReference().GetFileReferenceByPath(path);
                break;

            case LocalConstants.DirectoryParameterSetName:
                fileToBeDownloaded = this.Directory.GetFileReferenceByPath(path);
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            string resolvedDestination = this.GetUnresolvedProviderPathFromPSPath(
                string.IsNullOrWhiteSpace(this.Destination) ? "." : this.Destination);

            FileMode mode = this.Force ? FileMode.Create : FileMode.CreateNew;
            string   targetFile;

            if (LocalDirectory.Exists(resolvedDestination))
            {
                // If the destination pointed to an existing directory, we
                // would download the file into the folder with the same name
                // on cloud.
                targetFile = LocalPath.Combine(resolvedDestination, fileToBeDownloaded.GetBaseName());
            }
            else
            {
                // Otherwise we treat the destination as a file no matter if
                // there's one existing or not. The overwrite behavior is configured
                // by FileMode.
                targetFile = resolvedDestination;
            }

            this.RunTask(async taskId =>
            {
                var downloadJob = new TransferJob(
                    new TransferLocation(fileToBeDownloaded),
                    new TransferLocation(targetFile),
                    TransferMethod.SyncCopy);

                var progressRecord = new ProgressRecord(
                    this.OutputStream.GetProgressId(taskId),
                    string.Format(CultureInfo.CurrentCulture, Resources.ReceiveAzureFileActivity, fileToBeDownloaded.GetFullPath(), targetFile),
                    Resources.PrepareDownloadingFile);

                await this.RunTransferJob(downloadJob, progressRecord);

                if (this.PassThru)
                {
                    this.OutputStream.WriteObject(taskId, fileToBeDownloaded);
                }
            });
        }
Ejemplo n.º 8
0
        public async Task TestGitStagedModifiedStatus(bool withDiff)
        {
            var    repo2    = (GitRepository)Repo;
            var    testFile = "file1";
            var    testPath = LocalPath.Combine("file1");
            string difftext = string.Empty;

            await AddFileAsync(testFile, "test 1\n", true, true);

            // new file added and committed
            var status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsFalse(status.HasLocalChanges);
            Assert.AreEqual(VersionStatus.Versioned, status.Status);
            if (withDiff)
            {
                Assert.IsTrue(string.IsNullOrEmpty((await repo2.GenerateDiffAsync(testPath, status)).Content));
            }

            // modify the file without staging
            File.AppendAllText(testPath, "test 2\n");
            status = await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache);

            Assert.IsTrue(status.HasLocalChanges);
            Assert.AreEqual(VersionStatus.Modified | VersionStatus.Versioned, status.Status);

            if (withDiff)
            {
                difftext = @"--- a/file1
+++ b/file1
@@ -1 +1,2 @@
 test 1
+test 2
".Replace("file1", testFile);
                var diff = await repo2.GenerateDiffAsync(testPath, status);

                Assert.AreEqual(difftext, diff.Content);
            }

            // stage changes
            LibGit2Sharp.Commands.Stage(repo2.RootRepository, testPath);
            Assert.IsTrue(status.Equals(await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache)));

            if (withDiff)
            {
                var diff = await repo2.GenerateDiffAsync(testPath, status);

                Assert.AreEqual(difftext, diff.Content);
            }

            // modify the file again
            File.AppendAllText(testPath, "test 3\n");
            Assert.IsTrue(status.Equals(await Repo.GetVersionInfoAsync(testPath, VersionInfoQueryFlags.IgnoreCache)));


            if (withDiff)
            {
                difftext = @"--- a/file1
+++ b/file1
@@ -1 +1,3 @@
 test 1
+test 2
+test 3
".Replace("file1", testFile);
                var diff = await repo2.GenerateDiffAsync(testPath, status);

                Assert.AreEqual(difftext, diff.Content);
            }
        }