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!
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.
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.
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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!