Skip to content

Commit

Permalink
Fixed default branch assumption
Browse files Browse the repository at this point in the history
  • Loading branch information
parthlr committed Oct 27, 2024
1 parent 2fa2429 commit e6e38c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions StardewValleyManager/Services/GitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ public class GitService

private string _clientID;

private string _branchName;

private SettingsService _settingsService;

public GitService(SettingsService settingsService)
{
_settingsService = settingsService;

AuthToken = settingsService.GetSettingsValue("gitToken");
User = settingsService.GetSettingsValue("username");
RepositoryName = settingsService.GetSettingsValue("repository");

_clientID = settingsService.GetSettingsValue("clientID");
_branchName = settingsService.GetSettingsValue("defaultBranch");

Client = new GitHubClient(new ProductHeaderValue("StardewValleyManager"));

Expand Down Expand Up @@ -79,6 +86,7 @@ public async Task CheckAndCreateRepository(string RepositoryName)
if (r.Name.Equals(RepositoryName))
{
repoExists = true;
_branchName = r.DefaultBranch;
break;
}
}
Expand All @@ -92,12 +100,15 @@ public async Task CheckAndCreateRepository(string RepositoryName)
Private = false
};
Repository context = await Client.Repository.Create(newRepository);
_branchName = context.DefaultBranch;
System.Diagnostics.Debug.WriteLine($"New repository {RepositoryName} was created for user {User}");
}
else
{
System.Diagnostics.Debug.WriteLine($"Repository {RepositoryName} already exists for user {User}");
}

_settingsService.UpdateSettingsValue("defaultBranch", _branchName, true);
}

public async Task CommitAllSaves(string[] Saves)
Expand Down Expand Up @@ -202,7 +213,7 @@ public async Task<string> GetCommitContent(string FileName, string CommitSha)

public async Task<Commit> GetLatestCommit()
{
string branchHead = "heads/master";
string branchHead = $"heads/{_branchName}";

Reference headReference = await Client.Git.Reference.Get(User, RepositoryName, branchHead);
Commit latestCommit = await Client.Git.Commit.Get(User, RepositoryName, headReference.Object.Sha);
Expand Down Expand Up @@ -255,7 +266,7 @@ private async Task<Reference> CreateNewCommit(string CommitMessage, Commit Lates

Commit commitResponse = await Client.Git.Commit.Create(User, RepositoryName, newCommit);

string branchHead = "heads/master";
string branchHead = $"heads/{_branchName}";
Reference savedReference = await Client.Git.Reference.Update(User, RepositoryName, branchHead, new ReferenceUpdate(commitResponse.Sha));

return savedReference;
Expand Down
1 change: 1 addition & 0 deletions StardewValleyManager/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<gitToken></gitToken>
<username></username>
<repository>StardewValleySaves</repository>
<defaultBranch></defaultBranch>
</settings>

0 comments on commit e6e38c8

Please sign in to comment.