I had to write a simple ColdFusion web page showing clickable Git feature branches for multiple Git repositories. This is for a group of testers so they can easily checkout branches on a remote server for testing. My <cfexecute>
works for showing the branches, checking out branches, and checking out tags. The problem is that new feature branches / commits never show up for them because I can't get $ git fetch
or $ git pull
to work. For some reason those timeout. I know it's not the ColdFusion timeout settings. I can run the fetch and pull manually using Git Bash on the remote server and they run in a few seconds. Git on the remote server has the credentials stored in the Window Credential Manager so I'm never prompted to sign in when using Git on the command line on the server itself. So why would $ git checkout <branch>
and $ git branch -a
commands work but fetch and pull not using this code...
<cffunction name="execute" access="public" returnformat="JSON">
<cfargument name="command" type="string" required="true">
<cfargument name="directory" type="string" required="true">
<cfexecute name = "C:\Windows\System32\cmd.exe"
arguments = '/C cd "#arguments.directory#" && "c:\Program Files\Git\cmd\git.exe" #arguments.command#'
timeout = "600" variable="message" errorVariable="error_message">
</cfexecute>
<cfreturn [arguments.directory, arguments.command, message, error_message]>
</cffunction>
Thanks!
The reason the CFexecute fails is because the git pull command is waiting for the user to specify a username and password when making the pull. To fix this go to https://github.com/settings/tokens to generate and access token, and then use that token to pass it to the pull URL, like this:
Jose Elias