Skip to content

Commit ac253a4

Browse files
authored
Merge pull request #55 from pleonex/feature/fix-pushDocs
Fix Push-Doc was not pushing the documentation
2 parents 931cb0e + 6e50b8a commit ac253a4

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/PleOps.Cake/documentation.cake

+29-7
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,29 @@ Task("Push-Doc")
4646
}
4747

4848
// TODO: [#6] Implement multi-version documentation
49-
string pushWorktreeName = "push-gh-pages";
49+
string worktreeName = "push-gh-pages";
5050
string committerName = "PleOps.Cake Bot";
5151
string committerEmail = "[email protected]";
5252

5353
using (Repository repo = new Repository(GitFindRootFromPath(".").FullPath)) {
5454
bool ownTree = false;
5555
Worktree tree = null;
56-
if (repo.Worktrees.Any(w => w.Name == pushWorktreeName)) {
56+
if (repo.Worktrees.Any(w => w.Name == worktreeName)) {
5757
Information("Re-use worktree");
58-
tree = repo.Worktrees[pushWorktreeName];
58+
tree = repo.Worktrees[worktreeName];
5959
} else {
6060
Information("Create worktree");
6161

6262
// libgit2sharp does not clean the refs and it complains if you run it again later
63-
string refPath = $"{repo.Info.Path}/refs/heads/{pushWorktreeName}";
63+
string refPath = $"{repo.Info.Path}/refs/heads/{worktreeName}";
6464
if (FileExists(refPath)) {
6565
Information("Deleting old ref");
6666
DeleteFile(refPath);
6767
}
6868

6969
CreateDirectory($"{info.ArtifactsDirectory}/tmp");
7070
tree = repo.Worktrees.Add(
71-
"origin/gh-pages",
72-
pushWorktreeName,
71+
worktreeName,
7372
$"{info.ArtifactsDirectory}/tmp/gh-pages",
7473
false); // no lock since it's not a portable media
7574
ownTree = true;
@@ -79,6 +78,29 @@ Task("Push-Doc")
7978
string treePath = treeRepo.Info.WorkingDirectory;
8079
Information($"Worktree at: {treePath}");
8180

81+
// LibGit2Sharp seems to have a bug where it creates the worktree branch
82+
// at the current HEAD (main branch), instead at the given reference.
83+
// So we do the checkout with a pull ourselves.
84+
var checkoutSettings = new ProcessSettings {
85+
Arguments = "checkout gh-pages",
86+
WorkingDirectory = treePath,
87+
};
88+
int checkoutResult = StartProcess("git", checkoutSettings);
89+
if (checkoutResult != 0) {
90+
Error("Error creating gh-pages branch");
91+
}
92+
93+
var pullSettings = new ProcessSettings {
94+
Arguments = "pull --ff-only origin gh-pages",
95+
WorkingDirectory = treePath,
96+
};
97+
int pullResult = StartProcess("git", pullSettings);
98+
if (pullResult != 0) {
99+
Error("Error pulling");
100+
}
101+
102+
Information($"Current branch: {treeRepo.Head.FriendlyName}");
103+
82104
// Clean directory so we don't keep old files
83105
// Just move temporary the .git file so it's not deleted.
84106
CopyFile($"{treePath}/.git", $"{info.ArtifactsDirectory}/tmp/.git");
@@ -111,10 +133,10 @@ Task("Push-Doc")
111133
Information("No changes detected, no new commits done");
112134
}
113135

114-
115136
if (ownTree) {
116137
Information("Prune worktree");
117138
repo.Worktrees.Prune(tree);
139+
repo.Branches.Remove(worktreeName);
118140
}
119141
}
120142
});

0 commit comments

Comments
 (0)