private static string GetBasePath(CliArgumentParser cli) { if (cli.HasOption(CliOptions.LocalArgument)) { return(Environment.CurrentDirectory); } return(Path.GetTempPath()); }
public static void Main(string[] args) { CliArgumentParser cli = new CliArgumentParser(args); if (!cli.IsCorrect) { Console.WriteLine(USAGE); Environment.ExitCode = WRONG_USAGE_CODE; return; } // The API is implemented to take advantage of the `cm shell' command // The first executed command will open a shell which will receive PlasticSCM commands // This optimizes the execution since the CLI environment is initialized only once. try { // Set up our work environment -> repository + workspace if (!PlasticAPI.CreateRepository(cli.RepositoryName, out mError)) { AbortProcess(); } string workspaceDir = Path.Combine(GetBasePath(cli), cli.WorkspaceName); if (Directory.Exists(workspaceDir)) { mError = string.Format("Targeted workspace directory already exists: {0}", workspaceDir); AbortProcess(); } Directory.CreateDirectory(workspaceDir); PlasticAPI.WorkingDirectory = workspaceDir; if (!PlasticAPI.CreateWorkspace(cli.WorkspaceName, cli.RepositoryName, out mError)) { AbortProcess(); } // Add some initial contents string filePath1 = Path.Combine(workspaceDir, "file 1.txt"); string filePath2 = Path.Combine(workspaceDir, "file2.txt"); File.WriteAllText(filePath1, "This is a sample file"); File.WriteAllText(filePath2, "This is another sample file"); if (!PlasticAPI.Add(filePath1, false, out mError)) { AbortProcess(); } if (!PlasticAPI.Add(filePath2, false, out mError)) { AbortProcess(); } if (!PlasticAPI.Checkin("Initial checkin", out mError)) { AbortProcess(); } long changesetToLabel = PlasticAPI.GetCurrentChangeset(); Console.WriteLine("First changeset: {0}", changesetToLabel); // Test partial checkin, checkout, undo checkout and move commands if (!PlasticAPI.Checkout(new string[] { filePath1 }, out mError)) { AbortProcess(); } CheckIsItemCheckedOut(filePath1); if (!PlasticAPI.UndoCheckout(new string[] { filePath1 }, out mError)) { AbortProcess(); } string moveDestination = Path.Combine(workspaceDir, "moved_file.txt"); if (!PlasticAPI.Move(filePath1, moveDestination, out mError)) { AbortProcess(); } if (!PlasticAPI.Checkout(new string[] { filePath2 }, out mError)) { AbortProcess(); } File.AppendAllText(filePath2, "\nThis file has been modified."); string directoryPath = Path.Combine(workspaceDir, "src"); Directory.CreateDirectory(directoryPath); string fooPath = Path.Combine(directoryPath, "foo.c"); File.WriteAllText(fooPath, HELLO_WORLD_C); string barPath = Path.Combine(directoryPath, "bar.c"); File.WriteAllText(barPath, SAMPLE_C_CODE); if (!PlasticAPI.Add(directoryPath, true, out mError)) { AbortProcess(); } CheckIsItemCheckedOut(directoryPath); CheckIsItemCheckedOut(fooPath); CheckIsItemCheckedOut(barPath); if (!PlasticAPI.Checkin(new string[] { filePath2, moveDestination }, "Adding a moved file and a modified one", out mError)) { AbortProcess(); } CheckIsItemCheckedOut(directoryPath); CheckIsItemCheckedOut(fooPath); CheckIsItemCheckedOut(barPath); if (!PlasticAPI.Checkin( "Check in all remaining contents -> a recursively added directory tree.", out mError)) { AbortProcess(); } // Update workspace contents and test the 'remove' command if (!PlasticAPI.GetLatest(out mError)) { AbortProcess(); } if (!PlasticAPI.Delete(filePath2, out mError)) { AbortProcess(); } if (!PlasticAPI.Checkin("Check in the deleted file", out mError)) { AbortProcess(); } // Create labels and exit if (!PlasticAPI.CreateLabel(changesetToLabel, "BL001", "First changeset ever!", out mError)) { AbortProcess(); } if (!PlasticAPI.CreateLabel( PlasticAPI.GetCurrentChangeset(), "BL002", "Last changeset for today", out mError)) { AbortProcess(); } Console.WriteLine("Sample run finished OK!"); } catch (Exception e) { Console.WriteLine(string.Format("ERROR: {0}", e.Message)); Environment.ExitCode = GENERIC_ERROR_CODE; } finally { CmdRunner.TerminateShell(); } }
public static void Main(string[] args) { CliArgumentParser cli = new CliArgumentParser(args); if(!cli.IsCorrect) { Console.WriteLine(USAGE); Environment.ExitCode = WRONG_USAGE_CODE; return; } // The API is implemented to take advantage of the `cm shell' command // The first executed command will open a shell which will receive PlasticSCM commands // This optimizes the execution since the CLI environment is initialized only once. try { // Set up our work environment -> repository + workspace if (!PlasticAPI.CreateRepository(cli.RepositoryName, out mError)) AbortProcess(); string workspaceDir = Path.Combine(GetBasePath(cli), cli.WorkspaceName); if(Directory.Exists(workspaceDir)) { mError = string.Format("Targeted workspace directory already exists: {0}", workspaceDir); AbortProcess(); } Directory.CreateDirectory(workspaceDir); PlasticAPI.WorkingDirectory = workspaceDir; if(!PlasticAPI.CreateWorkspace(cli.WorkspaceName, cli.RepositoryName, out mError)) AbortProcess(); // Add some initial contents string filePath1 = Path.Combine(workspaceDir, "file 1.txt"); string filePath2 = Path.Combine(workspaceDir, "file2.txt"); File.WriteAllText(filePath1, "This is a sample file"); File.WriteAllText(filePath2, "This is another sample file"); if(!PlasticAPI.Add(filePath1, false, out mError)) AbortProcess(); if(!PlasticAPI.Add(filePath2, false, out mError)) AbortProcess(); if(!PlasticAPI.Checkin("Initial checkin", out mError)) AbortProcess(); long changesetToLabel = PlasticAPI.GetCurrentChangeset(); Console.WriteLine("First changeset: {0}", changesetToLabel); // Test partial checkin, checkout, undo checkout and move commands if(!PlasticAPI.Checkout(new string[] { filePath1 }, out mError)) AbortProcess(); CheckIsItemCheckedOut(filePath1); if(!PlasticAPI.UndoCheckout(new string[]{ filePath1 }, out mError)) AbortProcess(); string moveDestination = Path.Combine(workspaceDir, "moved_file.txt"); if(!PlasticAPI.Move(filePath1, moveDestination, out mError)) AbortProcess(); if(!PlasticAPI.Checkout(new string[] { filePath2 }, out mError)) AbortProcess(); File.AppendAllText(filePath2, "\nThis file has been modified."); string directoryPath = Path.Combine(workspaceDir, "src"); Directory.CreateDirectory(directoryPath); string fooPath = Path.Combine(directoryPath, "foo.c"); File.WriteAllText(fooPath, HELLO_WORLD_C); string barPath = Path.Combine(directoryPath, "bar.c"); File.WriteAllText(barPath, SAMPLE_C_CODE); if(!PlasticAPI.Add(directoryPath, true, out mError)) AbortProcess(); CheckIsItemCheckedOut(directoryPath); CheckIsItemCheckedOut(fooPath); CheckIsItemCheckedOut(barPath); if(!PlasticAPI.Checkin(new string[] { filePath2, moveDestination }, "Adding a moved file and a modified one", out mError)) { AbortProcess(); } CheckIsItemCheckedOut(directoryPath); CheckIsItemCheckedOut(fooPath); CheckIsItemCheckedOut(barPath); if(!PlasticAPI.Checkin( "Check in all remaining contents -> a recursively added directory tree.", out mError)) { AbortProcess(); } // Update workspace contents and test the 'remove' command if(!PlasticAPI.GetLatest(out mError)) AbortProcess(); if(!PlasticAPI.Delete(filePath2, out mError)) AbortProcess(); if(!PlasticAPI.Checkin("Check in the deleted file", out mError)) AbortProcess(); // Create labels and exit if(!PlasticAPI.CreateLabel(changesetToLabel, "BL001", "First changeset ever!", out mError)) AbortProcess(); if(!PlasticAPI.CreateLabel( PlasticAPI.GetCurrentChangeset(), "BL002", "Last changeset for today", out mError)) { AbortProcess(); } Console.WriteLine("Sample run finished OK!"); } catch (Exception e) { Console.WriteLine(string.Format("ERROR: {0}", e.Message)); Environment.ExitCode = GENERIC_ERROR_CODE; } finally { CmdRunner.TerminateShell(); } }
private static string GetBasePath(CliArgumentParser cli) { if (cli.HasOption(CliOptions.LocalArgument)) return Environment.CurrentDirectory; return Path.GetTempPath(); }