system() command does not return git output

Hi, I am generating a markdown page in a shiny app to document the version of the code I am using:

remote.url <- system("git config --get remote.origin.url", intern=TRUE)
cat("GIT Repository (public):\n", remote.url, "\n")

which previously worked perfectly. However, the output I get now is:

## Warning in system("git config --get remote.origin.url", intern = TRUE):
## running command 'git config --get remote.origin.url' had status 1

However, when I run the git command "git config --get remote.origin.url" in the bash terminal in the folder of the shiny server (/srv/shiny-server/dhub/), I get the expected output:

git config --get remote.origin.url
Bitbucket

The only recent change was an upgrade to R version 4.4.1 from some previous 4.x.x version.

Any advice to get the correct output via the system command in R?

Kr, Shiny

Hi,

My first guess would be that during execution the working directory is not the project root folder and thus the git project cannot be found.

Maybe try and use system("git -C <path> config --get remote.origin.url", intern=TRUE) and provide the project folder path where git is.

Hope this helps,
PJ

Dear @pieterjanvc ,

thanks, your advice was half of the solution! I had to set the correct working directory as you suggested because the markdown file was in a sub-directory.

However, it seems that there was also an issue with dubious ownership. Since I run git commands in the shiny app (ie as "shiny" user), but I cloned the repo as a different user , eg "devusr", git chokes.

I could replicate the error by logging in as "shiny" user with sudo su shiny and executing the git commands.

Git itself noted the problem and suggested as a solution to add an exception:

"git config --global --add safe.directory /srv/shiny-server/dhub"

However, this did not fix the problem either.

Following, this advice [1], I tried:

git config --system --add safe.directory '*'

which finally fixed the problem!

However, I am not 100% sure what the security implications are and whether there is a better solution.

Comments welcome!

Kr, Shiny

Refs:
[1] https://community.atlassian.com/t5/Bitbucket-questions/Getting-code-128-fatal-detected-dubious-ownership-in-repository/qaq-p/2373506

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.