3

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!

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
gfrobenius
  • 3,987
  • 8
  • 34
  • 66
  • 1
    Does the ColdFusion service run with the same user as your manual command line test? – Alex Dec 11 '18 at 21:10
  • @alex No it does not. I was thinking that might be the issue. How would I make those Git credentials available to the system running the ColdFusion service? Or is there a better way to authenticate if that is the issue? – gfrobenius Dec 11 '18 at 21:30
  • 2
    Log in as said user and add the credentials? Or you could authenticate with an RSA key using `ssh` with `-i identity_file`. Or you simply provide `username:password` via HTTP Basic Auth when working with the repo - but be aware of the insecure nature of this plain text password approach. – Alex Dec 11 '18 at 22:08
  • un:pw worked (I'm using https, not http), the fetch and pulls appear to be working. Thanks! But now I keep getting this message so I guess I need to figure out how to setup name/email when it's not running under my account as well. I will start a new question if I can't figure it out. `*** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'SYSTEM@WIN-BRJKSI0MVLI.(none)')` – gfrobenius Dec 11 '18 at 22:33
  • I found the `--system` option, all good! – gfrobenius Dec 11 '18 at 22:53

1 Answers1

1

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:

git pull https://MY_TOKEN_GOES_HERE:x-oauth-basic@github.com/myUser/myRepository master

Jose Elias

fcdt
  • 2,371
  • 5
  • 14
  • 26
Jose Elias
  • 11
  • 1