Git Sync branch name issues

Product: PowerShell Universal
Version: 2.0.0

Working on testing out the Git sync in my lab environment against an Azure devops git repo. I setup a fresh repo, with main as the default branch name, setup my appsettings.json and restarted the service. Initially I was getting some failure errors, and finally settled on clearing the .git folder from the local system and restarted the server. When I did this, I got a successful sync! However, it’s synced up a ‘master’ branch instead of main, despite the fact that I specified branch name in the git section on appsettings.json.

Has anyone else run into this problem?

Just tested this on version 2.0.3 and had the same results.

Here are my my settings.

"Data": {
   "RepositoryPath": "%ProgramData%\\UniversalAutomation\\Repository",
   "ConnectionString": "filename=%ProgramData%\\UniversalAutomation\\database.db;upgrade=true",
   "GitRemote": "",
   "GitUserName": "myuser",
   "GitPassword": "PAT", 
   "GitBranch": "dev",
   "GitSyncBehavior": "TwoWay",
   "ConfigurationScript": ""

I tested a few different times once without the dev branch and one I created. Both times it just used the master branch

I’ll take a look. I opened an issue for it here: Git sync branch issue · Issue #273 · ironmansoftware/issues · GitHub

I’ve haven’t been able to reproduce this. I have tried both GitHub and Azure DevOps repos and it works correctly.

In both instances, I have deleted the repository and started completely fresh. Then I set all the parameters in appsettings.json and start up Universal. It successfully clones the proper branch. In both cases I did not have a master branch and only a main\dev branch.

Here’s my log.

info: UniversalAutomation.Git.GitService[0]       
      Git repository does not exist. Initializing.
2021-07-05 01:02:29 [INFO]  (Hangfire.Server.BackgroundServerProcess) Server laptop-496lauk8:24276:578f18e6 successfully announced in 195.5741 ms
2021-07-05 01:02:29 [INFO]  (Hangfire.Server.BackgroundServerProcess) Server laptop-496lauk8:24276:578f18e6 is starting the registered dispatchers: ServerWatchdog, ServerJobCancellationWatcher, ExpirationManager, CountersAggregator, Worker, DelayedJobScheduler, RecurringJobScheduler...
2021-07-05 01:02:29 [INFO]  (Hangfire.Server.BackgroundServerProcess) Server laptop-496lauk8:24276:578f18e6 all the dispatchers started
info: UniversalAutomation.GitSyncService[0]
      Starting sync...
info: UniversalAutomation.GitSyncService[0]
      Latest commit Id: 4be87e674825debfc66b5e4022795b9160832491, Number of changes since last sync: 1
info: UniversalAutomation.GitSyncService[0]
      Sync done. Status Id: 1

I am using the 2.1.2 nightly build to test this but nothing has changed within the git service in a long time so I can’t imagine there are differences between the 2.0.3 build and this one.

What would be helpful is a log from either of your environments.

Replication steps:

  1. Deleted .git from “c$\ProgramData\UniversalAutomation\Repository”
  2. Updated appsetting.json
"Data": {
   "RepositoryPath": "%ProgramData%\\UniversalAutomation\\Repository",
   "ConnectionString": "filename=%ProgramData%\\UniversalAutomation\\database.db;upgrade=true",
   "GitRemote": "",
   "GitUserName": "PSU-Test",
   "GitPassword": "PAT", 
   "GitBranch": "test",
   "GitSyncBehavior": "TwoWay",
   "ConfigurationScript": ""
  1. Committed everything under “c$\ProgramData\UniversalAutomation\Repository” to the devops repo
  2. Started PSU
  3. It then created a master branch.

The following commit id is what is showing up in azure…

21-07-06T11:48:01.3215264-05:00  [INF] Script has 0 jobs to delete. (1676cac2)
2021-07-06T11:48:01.3215549-05:00  [INF] Groom date is: 6/6/2021 4:48:01 PM (6128188c)
2021-07-06T11:48:01.3225629-05:00  [INF] Old jobs: 0 (be620771)
2021-07-06T11:48:01.3227991-05:00  [INF] Finished groom job. (ccb4f234)
2021-07-06T11:48:02.3984189-05:00  [INF] Latest commit Id: c9c084d510b11c25fceedbf0906a281046977bb8, Number of changes since last sync: 4 (e6241a48)
2021-07-06T11:48:02.4000148-05:00  [INF] Sync done. Status Id: 2 (ed5396a1)
2021-07-06T11:48:02.4338962-05:00  [INF] Starting job using Process. (4d0a5a43)
2021-07-06T11:48:13.9365985-05:00  [INF] Starting job using Process. (4d0a5a43)

Also tried the same steps with a fresh branch called test. Only thing committed was a readme.

2021-07-06T12:02:40.9850251-05:00  [INF] Starting sync... (a444e9b8)
2021-07-06T12:02:41.3155035-05:00  [ERR] Failed to sync: "The current branch is configured to merge with the reference 'refs/heads/master' from the remote, but this reference was not fetched." "   at LibGit2Sharp.Repository.MergeFetchedRefs(Signature merger, MergeOptions options)
   at LibGit2Sharp.Commands.Pull(Repository repository, Signature merger, PullOptions options)
   at UniversalAutomation.Git.GitService.Pull() in D:\a\universal\universal\src\UniversalAutomation.Git\GitService.cs:line 236
   at UniversalAutomation.GitSyncService.TrySync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 90
   at UniversalAutomation.GitSyncService.Sync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 60" (2d6ed692)
2021-07-06T12:02:44.0523504-05:00  [INF] Starting job using Process. (4d0a5a43)
2021-07-06T12:02:44.2349491-05:00  [INF] Now listening on: "http://[::]:5000" (d826f4b8)
2021-07-06T12:02:44.2352097-05:00  [INF] Application started. Hosting environment: "Production"; Content root path: "C:\Program Files (x86)\Universal\" (9029d6f8)
1 Like

I stopped PSU service and deleted the .git folder from the repository. Then I used vscode to confirm source control wasn’t picking up anything git related in that repository folder, verified my appsettings.json git options (specifically branch name), and proceeded to start PSU Service. It creates a master branch as part of the startup.

Thanks. I’m jumping on a call with @mikedhanson today to see if I can get a better idea of what’s happening. I still can’t reproduce myself.

I actually searched the entire code-base for the word “master” and it only appears in the documentation so it must be some side effect of the git library that PSU uses.

@dcherry88 @mikedhanson

I reproduced this.

The problem is that if the repository directory has any files in it, it will push to master rather than the selected branch. I’ve fixed that.

If the directory is completely empty, it will clone from the desired branch. This is what I kept doing.

I guess my question is what you’d expect expect this behavior to be. If you have files locally and git isn’t initialized, it’s going to attempt to push changes to the remote during start up (I just added a check to make sure it doesn’t do this if OneWay is on). If your repository directory is empty it will only try to clone.

I was experiencing the same issues described above.

Thanks for taking time to dig into this and jumping on a call, we will be looking forward to testing the next release.

2.1.2 is available and has this fix.


Looks like this is now working as expected. Thanks :slight_smile:

Wanted to followup and confirm that it’s working for me now as well too on version 2.1.2. Thanks Adam

1 Like