Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle file deletions #11

Open
IvanJosipovic opened this issue Apr 15, 2019 · 4 comments
Open

Handle file deletions #11

IvanJosipovic opened this issue Apr 15, 2019 · 4 comments

Comments

@IvanJosipovic
Copy link

When a file is deleted in the source, it should also be removed form the git repo. Currently, deleted files remain in the git repo.

@IvanJosipovic
Copy link
Author

In case anyone is intersted, I used the code below.

# Get inputs.
$docPath = "$(Build.ArtifactStagingDirectory)/dist/*";
$githubusername = "$(GIT_NAME)";
$githubemail = "$(GIT_EMAIL)";
$githubaccesstoken = "$(GIT_PAT)";
$repositoryname = "$(GIT_REPO)";
$commitMessage = "Automated Release $(Build.BuildId)";
$branchName = "gh-pages";
$gitdirectory = "$(System.DefaultWorkingDirectory)/ghpages";

git config --global core.autocrlf false
git config --global user.email $githubemail
git config --global user.name $githubemail

Write-Host "Cloning existing GitHub repository"
git clone https://${githubusername}:[email protected]/$githubusername/$repositoryname.git --branch=$branchName $gitdirectory --quiet

if ($lastexitcode -gt 0)
{
    Write-Host "##vso[task.logissue type=error;]Unable to clone repository - check username, access token and repository name. Error code $lastexitcode"
    [Environment]::Exit(1)
}

Set-Location $gitdirectory

Write-Host "Clearing Data"
git rm -r '*'

Write-Host "Copying new documentation into branch"
Copy-Item $docPath $gitdirectory -Recurse -Force
git add '*'

Write-Host "Committing the GitHub repository"
git commit --allow-empty -m $commitMessage

if ($lastexitcode -gt 0)
{
    Write-Host "##vso[task.logissue type=error;]Error committing - see earlier log, error code $lastexitcode"
    [Environment]::Exit(1)
}

git push --quiet

if ($lastexitcode -gt 0)
{
    Write-Host "##vso[task.logissue type=error;]Error pushing to $branchName branch, probably an incorrect Personal Access Token, error code $lastexitcode"
    [Environment]::Exit(1)
}

@JamesRandall
Copy link
Owner

JamesRandall commented Apr 26, 2019

Thanks. I'll reopen this and look to get that merged.
(Sorry it took me a while to reply - I was on a cycling / working break and had to heavily prioritise my work as a result).

@JamesRandall JamesRandall reopened this Apr 26, 2019
@johannesegger
Copy link

I'm somewhat glad that you don't do a git rm -r '*' at the beginning, because I have two pipelines that both add a specific part of the app (one provides the UI (HTML + JS), the other one the data (some JSON files)). So I would be very happy if you could consider this use case when fixing this issue.

@ronaldbosma
Copy link

I created a PR for this: #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants