SAPIEN Editors – Working with Git Repositories

This blog post will get you started working with Git repositories in either of our SAPIEN editors—PowerShell Studio or PrimalScript.

In the following scenario, I will use an existing Git repository stored in Azure DevOps to demonstrate the process of cloning the repository to a local folder, committing some changes, and updating the changes back to the Azure DevOps repository.

Requirements

You need to install Git before working with Git repositories in either of our SAPIEN editors. Use the following link to download and install Git for Windows.

Configuring Git in PowerShell Studio or PrimalScript

After installing Git, you will need to set up Git source control in PowerShell Studio or PrimalScript.

In PowerShell Studio, on the Home ribbon in the Windows section, select Options (or File > Options). Then select the Source Control tab at the bottom:

In PrimalScript, select File > Options. Under the Source Control section, select General:

In the Options > Source Control section of either SAPIEN editor:

  1. Under Universal Version Control System select Git.
  2. Click OK to save the Options changes.
  3. Restart the editor.

In PowerShell Studio, the Git menu is in the Source Control ribbon tab:

In PrimalScript, the Git menu is in the Tools ribbon tab:

All options in the menu are preset Git commands.

There are two additional options if you want to do more with Git:

  • Shell – Git command line
  • GUI – Git GUI application
Showing both the GUI and Git Shell

Prior to cloning an existing repository

First, a placeholder for the cloned repository needs to exist on the local machine. For this example, I created an empty folder named GitRepoPowerShellScripts01.

Now I can proceed to clone my Git repository from my Azure DevOps site. Keep in mind that I have previously set my permissions to access this repository.

Working with the Repository Source Code

Working with Git is as simple as following the SDLC (Software Development Life-Cycle):

  1. Clone a repository to a local folder.
  2. Diff to list the code changes.
  3. Commit the changes in the local repository.
  4. Push the changes back to the remote repository.

Note: The Git menu options are enabled when a script is open in the editor.

Clone

This option is used to copy the remote repository to the local drive, and it will prompt for the following information:

  1. Name of a new directory to clone into.
  2. The Git remote repository address.
Cloning first prompt
Cloning second prompt

When the cloning process completes, the source code will be available for editing.

Cloning message

Now I can open a script and start making changes to the code.

Diff

This option gives a list of the changes made to the code. In either SAPIEN editor, the results will be displayed in the Tool Output panel:

PowerShell Studio
PrimalScript

Commit

After making changes to the code, I will use the Commit button to mark the changes in the local repository.

The Commit option will prompt for the following information:
1. Enter a commit message.

Commit Prompt
Commit result

Push

The Push option will send the changes back to the remote repository. There is no prompt for this option.

The results display in the Tool Output panel:

Push results

You can go back to the remote repository to confirm that the source code was updated.

Summary

Both of our SAPIEN editors—PowerShell Studio and PrimalScript—provide the essential options for working with Git repositories. Additionally, we have included the Git command line for more complex commands, and also the Git GUI application for fast interaction with the source code.

References

Feedback

As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com