BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi there.

 

I am using the function GIT_INDEX_ADD to stage files in a local git repo and it is working fine using the following snippet from SAS Viya 3.5 documentation.

 

data _null_;
   n = git_status("your-repository");                                      /**/
   rc = git_index_add("your-repository", "your-file", "file-attribute");   /**/
   rc = git_status_free("your-repository")
   n = git_status("your-repository");                                      /**/
run;

The thing is I want to stage all files in the repo without previous knowledge of the filename like the git CLI command " git add * "  does.

 

Does anyone knows if this is possible using SAS StudioV for Viya 3.5?

 

Cheers!

1 ACCEPTED SOLUTION

Accepted Solutions
gwootton
SAS Super FREQ

The asterisk is a shell function that expands to all files in a given path. For example if you run "echo *", the shell will return a list of all files. So git add is still being given all the file names, we just need to replicate that * behavior.
I think what you'd want to do is create a data set of all files in a given path, then use the data step to run git_index_add on each of them. The way I've done this in the past is here (creating a dataset called dirlist from the path defined in the macro variable &path). This does require XCMD so we can run the ls command.

filename DIRLIST pipe "ls &path";
data dirlist;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;


I think you could then add a "set dirlist;" to your data _null_ data step, and instead of "your-file" use file_name.

--
Greg Wootton | Principal Systems Technical Support Engineer

View solution in original post

2 REPLIES 2
gwootton
SAS Super FREQ

The asterisk is a shell function that expands to all files in a given path. For example if you run "echo *", the shell will return a list of all files. So git add is still being given all the file names, we just need to replicate that * behavior.
I think what you'd want to do is create a data set of all files in a given path, then use the data step to run git_index_add on each of them. The way I've done this in the past is here (creating a dataset called dirlist from the path defined in the macro variable &path). This does require XCMD so we can run the ls command.

filename DIRLIST pipe "ls &path";
data dirlist;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;


I think you could then add a "set dirlist;" to your data _null_ data step, and instead of "your-file" use file_name.

--
Greg Wootton | Principal Systems Technical Support Engineer
alisio_meneses
Quartz | Level 8

Hi there @gwootton.

 

Sadly I lack the privilege needed to run XCMD commands so I had to adapt your suggestion a bit and ended up with a script that does the same thing but doesn't use XCMD command.

 

 

/* Create dataset containing list of files */
data dirlist; length fref $8 fname $200; did=filename(fref, "/git_repo_folder"); did=dopen(fref); do i=1 to dnum(did); fname=dread(did, i); output; end; did=dclose(did); did=filename(fref); keep fname; run; /* Add list of files to index */ data _null_; set dirlist; rc = git_index_add("/git_repo_folder", fname, "new"); n = git_status_free("/git_repo_folder"); run;

 

Thanks for your reply. Your tip was very helpful!

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 2 replies
  • 685 views
  • 2 likes
  • 2 in conversation