-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from pleonex/feature/fix-pushDocs
Fix Push-Doc was not pushing the documentation
- Loading branch information
Showing
1 changed file
with
29 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,30 +46,29 @@ Task("Push-Doc") | |
} | ||
|
||
// TODO: [#6] Implement multi-version documentation | ||
string pushWorktreeName = "push-gh-pages"; | ||
string worktreeName = "push-gh-pages"; | ||
string committerName = "PleOps.Cake Bot"; | ||
string committerEmail = "[email protected]"; | ||
|
||
using (Repository repo = new Repository(GitFindRootFromPath(".").FullPath)) { | ||
bool ownTree = false; | ||
Worktree tree = null; | ||
if (repo.Worktrees.Any(w => w.Name == pushWorktreeName)) { | ||
if (repo.Worktrees.Any(w => w.Name == worktreeName)) { | ||
Information("Re-use worktree"); | ||
tree = repo.Worktrees[pushWorktreeName]; | ||
tree = repo.Worktrees[worktreeName]; | ||
} else { | ||
Information("Create worktree"); | ||
|
||
// libgit2sharp does not clean the refs and it complains if you run it again later | ||
string refPath = $"{repo.Info.Path}/refs/heads/{pushWorktreeName}"; | ||
string refPath = $"{repo.Info.Path}/refs/heads/{worktreeName}"; | ||
if (FileExists(refPath)) { | ||
Information("Deleting old ref"); | ||
DeleteFile(refPath); | ||
} | ||
|
||
CreateDirectory($"{info.ArtifactsDirectory}/tmp"); | ||
tree = repo.Worktrees.Add( | ||
"origin/gh-pages", | ||
pushWorktreeName, | ||
worktreeName, | ||
$"{info.ArtifactsDirectory}/tmp/gh-pages", | ||
false); // no lock since it's not a portable media | ||
ownTree = true; | ||
|
@@ -79,6 +78,29 @@ Task("Push-Doc") | |
string treePath = treeRepo.Info.WorkingDirectory; | ||
Information($"Worktree at: {treePath}"); | ||
|
||
// LibGit2Sharp seems to have a bug where it creates the worktree branch | ||
// at the current HEAD (main branch), instead at the given reference. | ||
// So we do the checkout with a pull ourselves. | ||
var checkoutSettings = new ProcessSettings { | ||
Arguments = "checkout gh-pages", | ||
WorkingDirectory = treePath, | ||
}; | ||
int checkoutResult = StartProcess("git", checkoutSettings); | ||
if (checkoutResult != 0) { | ||
Error("Error creating gh-pages branch"); | ||
} | ||
|
||
var pullSettings = new ProcessSettings { | ||
Arguments = "pull --ff-only origin gh-pages", | ||
WorkingDirectory = treePath, | ||
}; | ||
int pullResult = StartProcess("git", pullSettings); | ||
if (pullResult != 0) { | ||
Error("Error pulling"); | ||
} | ||
|
||
Information($"Current branch: {treeRepo.Head.FriendlyName}"); | ||
|
||
// Clean directory so we don't keep old files | ||
// Just move temporary the .git file so it's not deleted. | ||
CopyFile($"{treePath}/.git", $"{info.ArtifactsDirectory}/tmp/.git"); | ||
|
@@ -111,10 +133,10 @@ Task("Push-Doc") | |
Information("No changes detected, no new commits done"); | ||
} | ||
|
||
|
||
if (ownTree) { | ||
Information("Prune worktree"); | ||
repo.Worktrees.Prune(tree); | ||
repo.Branches.Remove(worktreeName); | ||
} | ||
} | ||
}); |