BookmarkSubscribeRSS Feed
AlexGW
Fluorite | Level 6

In both SAS Viya and SAS 9.6 M6 (Enterprise guide) I have the following problem:

 

I can successfully clone an online repository with multiple branches onto my SAS server location using either GIT_CLONE or GITFN_CLONE.

 

However, I cannot checkout onto an existing branch using onto that branch name.

For example:

GITFN_CO_BRANCH( "path_to_repo", "v1Harry")

This tells me that:

ERROR: Return code from GIT is (4). revspec 'v1Harry' not found

 

However when we change to:

GITFN_CO_BRANCH( "path_to_repo", "origin/v1Harry")

This works:

NOTE: Branch "origin/v1Harry" successfully checked out.

 

But the big problem now comes when we do a gitfn_status:

NOTE: Entry: README.md. Staged: True. Status: New.
NOTE: Entry: master_script.sas. Staged: True. Status: New.

 

Despite all files being on the branch online in the origin - git now thinks they are new.

This creates a huge problem if the repo has hundreds of files - it is nearly impossible to add them all back in as SAS has not allowed for git -A functionality in the GITFN_IDX_ADD function.

 

Finally let's say we go through the process of adding all these (unchanged files...) again and we commit and push from "origin/v1Harry"...

If we do this in SAS 9.4 we get this error:

ERROR: Return code from GIT is (9). object not found - no match for id (484541442f686f6d652f616c657867772f736173)

 

If we do this in Viya, then rather than branch v1Harry being updated on the origin, instead a new branch is created on the origin called "origin/v1Harry"

 

Am I doing something wrong?

 

Any help of advice would be most welcome.

 

BW,

Alex

 

3 REPLIES 3
baertman
Calcite | Level 5

Hi Alex,

 

I am currently facing exactly the same issue.

As you posted quite a long time ago and there seems to have been no answer, I am wondering whether you solve it ?

 

KR,

Etienne

 

baertman
Calcite | Level 5

well, I found a workaround but do not find it a suitable solution at long term.

Once I've cloned the repository, I am copying the ref from remotes/origin to heads within the local git metadata:

 

filename frefin  "&path.\.git\refs\remotes\origin\&targetBranch";
filename frefout "&path.\.git\refs\heads\&targetBranch";

data _null_ ;
     rc = fcopy('frefin', 'frefout');
     msg = sysmsg();
     put rc= msg=;
run;

and then successfully checking out the &targetBranch.:

data _null_;
     rc = git_branch_chkout("&path.", "&targetBranch.");
     put rc = ;
run;
littan
Calcite | Level 5

Create a local branch with the same name as the remote branch. Checking Out Branches 

  1. For example "dev" if you have remote branch "origin/dev".
  2. Checkout newly created local "dev" branch.
  3. Then when you pull changes it puls form remote "origin/dev".
data _null_;
   version = gitfn_version();        
   put version=;                   
run;

%let l_git_repo               = 'C:\Git\xxxxxxx';
%let l_git_uri                = 'https://?????/xxxxxxx.git';
%let l_git_user               = '???????';
%let l_git_pw                 = '{SAS005}???????';


/* Delete REPO  */
data _null_;
   rc = GITfn_DEL_REPO(&git_repo.);
   put rc=;
run;

/* Clone Repo */
data _null_;
   rc = GIT_CLONE (&l_git_uri., &l_git_repo., &l_git_user., &l_git_pw.);
   put rc=;
run;


/* Get Branch commit id from remote*/
%let l_git_branch             = 'dev';
%let l_git_branch_commit_id   = NA;
data _null_;
   infile %sysfunc(quote(%sysfunc(dequote(&l_git_repo.))/.git/refs/remotes/origin/%sysfunc(dequote(&l_git_branch.))));
   input;
   call symputx( 'l_git_branch_commit_id',quote(cats(_infile_)),'l');
   stop;
run;
%put &=l_git_branch_commit_id.;

/* create new local branch */ 
data _null_;
   rc = git_branch_new(&l_git_repo., &l_git_branch_commit_id., &l_git_branch., 0); 
   put rc=;
run;

/* chkout local branch */ 
data _null_;
   rc= git_branch_chkout(&l_git_repo.,&l_git_branch. );  
   put rc=;
run;

/* pull changes */ 
data _null_;
   rc= git_pull(&l_git_repo., &l_git_user., &l_git_pw.);             
   put rc=;                            
run;


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1725 views
  • 2 likes
  • 3 in conversation