Attention : This code requires administrator privileges.
The script initializes a working directory, then clones the `https://github.com/sasjs/core` repository into it. It then performs a series of operations on files: creating a new file (`somefile.txt`), modifying the content of an existing file (`readme.md`), and deleting another (`package.json`). After these changes, it uses the `mp_gitstatus` macro to check that three files are 'unstaged'. It then uses the `mp_gitadd` macro to stage these changes, and finally, it rechecks the Git status to ensure that the three files are now 'staged', using assertions (`mp_assert`) to validate each step of the process.
Data Analysis
Type : MIXED
The script interacts with an external source by cloning the Git repository `https://github.com/sasjs/core`. It also creates temporary internal datasets (`work.gitstatus`, `work.gitstatus2`) to store the results of Git commands and `work.test_results` for unit test assertions.
1 Code Block
MACRO CALL / SYSCALL
Explanation : This block initializes the macro variable `dir` with the path to a 'core' subdirectory created in the SAS working directory. It then uses the `GITFN_CLONE` function to clone the Git repository `https://github.com/sasjs/core` into this directory specified by `&dir`. This operation is a direct interaction with the file system and an external Git service.
Copied!
%let dir = %sysfunc(pathname(work))/core;
%put source clone rc=%sysfunc(GITFN_CLONE(https://github.com/sasjs/core,&dir));
Explanation : These SASJS macro calls simulate modifications in the cloned repository: `mf_writefile` is used to create a new file (`somefile.txt`) with content and to modify the content of an existing file (`readme.md`). The `mf_deletefile` macro deletes an existing file (`package.json`). These actions are direct file system manipulations to prepare changes for testing with Git commands.
Explanation : This block uses the `mp_gitstatus` macro to get the current status of files in the Git repository (`&dir`) and stores the results in the temporary dataset `work.gitstatus`. A `PROC SQL` then counts the number of unstaged files (where the 'staged' column is 'FALSE') and stores the result in the macro variable `test1`. Finally, the `mp_assert` macro is used to verify that this number is indeed 3, confirming that the previous modifications are correctly detected as unstaged by Git.
Copied!
%mp_gitstatus(&dir,outds=work.gitstatus)
%let test1=0;
proc sql noprint;
select count(*) into: test1 from work.gitstatus where staged='FALSE';
%mp_assert(
iftrue=(&test1=3),
desc=3 changes are ready to add,
outds=work.test_results
)
1
%mp_gitstatus(&dir,outds=work.gitstatus)
2
3
%let test1=0;
4
PROC SQL noprint;
5
select count(*) into: test1 from work.gitstatus where staged='FALSE';
6
7
%mp_assert(
8
iftrue=(&test1=3),
9
desc=3 changes are ready to add,
10
outds=work.test_results
11
)
4 Code Block
MACRO CALL
Explanation : The `mp_gitadd` macro is called to add the modified files (identified by the `work.gitstatus` dataset) to the Git staging area in the repository specified by `&dir`. The parameter `mdebug=&sasjs_mdebug` potentially activates debug mode for the macro.
Explanation : After the add operation, this block calls `mp_gitstatus` again to get the new status of files in the repository (`&dir`), storing the results in the temporary dataset `work.gitstatus2`. A second `PROC SQL` counts the files where the 'staged' column is 'TRUE' (i.e., staged files) and stores the result in `test2`. The `mp_assert` macro is used to confirm that 3 files are now 'staged', thus validating the success of the `mp_gitadd` operation.
Copied!
%mp_gitstatus(&dir,outds=work.gitstatus2)
%let test2=0;
proc sql noprint;
select count(*) into: test2 from work.gitstatus2 where staged='TRUE';
%mp_assert(
iftrue=(&test2=3),
desc=3 changes were added,
outds=work.test_results
)
1
%mp_gitstatus(&dir,outds=work.gitstatus2)
2
%let test2=0;
3
PROC SQL noprint;
4
select count(*) into: test2 from work.gitstatus2 where staged='TRUE';
5
6
%mp_assert(
7
iftrue=(&test2=3),
8
desc=3 changes were added,
9
outds=work.test_results
10
)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.