Search code examples
gitgithubwebhookspelican

Replacing remote git repo with local version having lost .git


I'm setting up automatic deployment of my Pelican blog using the newly-released Dropbox webhooks. Every time I change a file in Dropbox, it POSTs to my Heroku app, which does the following:

  1. Downloads the content from Dropbox
  2. Runs pelican over the new content to reproduce the blog. The output is to the local clone of my Github Pages repo.
    • This deletes all of the content that currently exists in the repo and replaces it with the newly generated blog. Unfortunately, this also deletes the .git directory.
  3. I've lost my .git/, so I run git init and readd the remote.
  4. I run git pull origin master to sync them up.
  5. Tracks all changes, new files, and deletions using git add -A ..
  6. Commits, pushes to Github.

The problem is facing is in Step 4, when I run git pull, it pulls all of the original information from the repo--including the files I want deleted. E.g., if I delete a post, it's properly deleted from the repo when I run pelican and it deletes the whoel folder and regenerates the blog without the file--but then that file reappears when I run git pull. I am not able to track which files are deleted because I lose my git history when .git/ is deleted when I run pelican.

At the end of the day, all I want to do is to run pelican, replace the entire contents of the repo, and then add all of the changes/deletsion/additions and then push the repo to Github. I will never need information on what's currently in the repo, so running git reset wouldn't be a problem for me, if helps. How can I do this?


Solution

  • Since there seemed to be no way to do what I was trying to do in git, what I ended up doing was setting pelican's DELETE_OUTPUT_DIRECTORY setting to False and then as part of my Fabric script running

    rm -rf *
    

    myself instead, which ignores dot-prefix files and directories, and therefore left .git/ alone. Then I could regenerate and add the new content to the repository, commit, and push without issue.