Giter VIP home page Giter VIP logo

ghp-import's Introduction

GitHub Pages Import

CI status CircleCI TravisCI

License Version

As part of gunicorn, Benoit Chesneau and Paul Davis were looking at how to host documentation. There's the obvious method of using GitHub's post-receive hook to trigger doc builds and rsync to a webserver, but we ended up wanting to try out github's hosting to make the whole interface a bit more robust.

GitHub Pages is a pretty awesome service that GitHub provides for hosting project documentation. The only thing is that it requires a gh-pages branch that is the site's document root. This means that keeping documentation sources in the branch with code is a bit difficult. And it really turns into a head scratcher for things like Sphinx that want to access documentation sources and code sources at the same time.

Then we stumbled across an interesting looking package called github-tools that looked almost like what we wanted. It was a tad complicated and more involved than we wanted but it gave us an idea. Why not just write a script that can copy a directory to the gh-pages branch of the repository. This saves us from even having to think about the branch and everything becomes magical.

This is what ghp-import was written for.

Big Fat Warning

This will DESTROY your gh-pages branch. If you love it, you'll want to take backups before playing with this. This script assumes that gh-pages is 100% derivative. You should never edit files in your gh-pages branch by hand if you're using this script because you will lose your work.

When used with a prefix, only files below the set prefix will be destroyed, limiting the above warning to just that directory and everything below it.

Usage

Usage: ghp-import [OPTIONS] DIRECTORY

Options:
  -n, --no-jekyll       Include a .nojekyll file in the branch.
  -c CNAME, --cname=CNAME
                        Write a CNAME file with the given CNAME.
  -m MESG, --message=MESG
                        The commit message to use on the target branch.
  -p, --push            Push the branch to origin/{branch} after committing.
  -x PREFIX, --prefix=PREFIX
                        The prefix to add to each file that gets pushed to the
                        remote. Only files below this prefix will be cleared
                        out. [none]
  -f, --force           Force the push to the repository.
  -o, --no-history      Force new commit without parent history.
  -r REMOTE, --remote=REMOTE
                        The name of the remote to push to. [origin]
  -b BRANCH, --branch=BRANCH
                        Name of the branch to write to. [gh-pages]
  -s, --shell           Use the shell when invoking Git. [False]
  -l, --follow-links    Follow symlinks when adding files. [False]
  -h, --help            show this help message and exit

Its pretty simple. Inside your repository just run ghp-import $DOCS_DIR where $DOCS_DIR is the path to the built documentation. This will write a commit to your gh-pages branch with the current documents in it.

If you specify -p it will also attempt to push the gh-pages branch to GitHub. By default it'll just run git push origin gh-pages. You can specify a different remote using the -r flag.

The -o option will discard any previous history and ensure that only a single commit is always pushed to the gh-pages branch. This is useful to avoid bloating the repository size and is highly recommended.

You can specify a different branch with -b. This is useful for user and organization page, which are served from the master branch.

Some Windows users report needing to pass Git commands through the shell which can be accomplished by passing -s.

The -l option will cause the import to follow symlinks for users that have odd configurations that include symlinking outside of their documentation directory.

Python Usage

You can also call ghp_import directly from your Python code as a library. The library has one public function ghp_import.ghp_import, which accepts the following arguments:

  • srcdir: The path to the built documentation (required).
  • remote: The name of the remote to push to. Default: origin.
  • branch: Name of the branch to write to. Default: gh-pages.
  • mesg: The commit message to use on the target branch. Default: Update documentation.
  • push: Push the branch to {remote}/{branch} after committing. Default: False.
  • prefix: The prefix to add to each file that gets pushed to the remote. Default: None.
  • force: Force the push to the repository. Default: False.
  • no_history: Force new commit without parent history. Default: False.
  • use_shell: Default: Use the shell when invoking Git. False.
  • followlinks: Follow symlinks when adding files. Default: False.
  • cname: Write a CNAME file with the given CNAME. Default: None.
  • nojekyll: Include a .nojekyll file in the branch. Default: False.

With Python's current working directory (cwd) inside your repository, do the following:

from ghp_import import ghp_import
ghp_import('docs', push=True, cname='example.com')

ghp-import's People

Contributors

andreacrotti avatar c-w avatar cshorler avatar davisp avatar dhimmel avatar hyperupcall avatar jkonecny12 avatar jwodder avatar ktomk avatar lancechentw avatar lgp171188 avatar lord63 avatar luisfernandobarrera avatar madjar avatar martinpaljak avatar mgedmin avatar pawamoy avatar pravic avatar timoroth avatar waylan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghp-import's Issues

nojekyll

this tool is awesome. I think it would be even more awesome if it created a .nojekyll file. Otherwise directories that begin with underscores will be ignored. And the sphinx-generated page will surely not use jekyll, right?

Thanks for the awesome project!

License the repository under an actual open source license

Currently, this repository is licensed under:

https://github.com/davisp/ghp-import/blob/0e2045e750569f67cbcd96e7e53dbfc865df747e/setup.py#L20

which reads:

https://github.com/davisp/ghp-import/blob/0e2045e750569f67cbcd96e7e53dbfc865df747e/LICENSE#L1-L11

Since ghp-import has a large user base that depends on it, I think it'd make sense to change the license to an actual open source license. Currently, for example, the lack of an open source license makes me less willing to contribute larger changes, since I don't want to spend time on something where there could be legal issues preventing future reuse.

I'd be happy to create a PR with a chosen license. I'd recommend MIT or BSD 3-Clause.

Irregular "error: Failed to rebase gh-pages branch" with --no-history

This issue follows #95 and #96.

I'm facing issues when using --no-history option.

Repository

Repo: https://github.com/geotribu/website/

GitHub Actions run: https://github.com/geotribu/website/runs/2161832176#step:8:12

Environment

sorry, my system is configured in French, so git messages are translated.

OS and Git

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

$ git --version
git version 2.31.0

guts:~/Git/Geotribu/website$ git status
Sur la branche master
Votre branche est à jour avec 'origin/master'.

rien à valider, la copie de travail est propre

Tool

(.venv) guts:~/Git/Geotribu/website$ ghp-import --version
Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: no such option: --version
(.venv) guts:~/Git/Geotribu/website$ ghp-import --help
Usage: ghp-import [OPTIONS] DIRECTORY

Options:
  -n, --no-jekyll       Include a .nojekyll file in the branch.
  -c CNAME, --cname=CNAME
                        Write a CNAME file with the given CNAME.
  -m MESG, --message=MESG
                        The commit message to use on the target branch.
  -p, --push            Push the branch to origin/{branch} after committing.
  -x PREFIX, --prefix=PREFIX
                        The prefix to add to each file that gets pushed to the
                        remote. [none]
  -f, --force           Force the push to the repository.
  -o, --no-history      Force new commit without parent history.
  -r REMOTE, --remote=REMOTE
                        The name of the remote to push to. [origin]
  -b BRANCH, --branch=BRANCH
                        Name of the branch to write to. [gh-pages]
  -s, --shell           Use the shell when invoking Git. [False]
  -l, --follow-links    Follow symlinks when adding files. [False]
  -h, --help            show this help message and exit

Reproduce

# build the website
(.venv) guts:~/Git/Geotribu/website$ mkdocs build --clean --config-file mkdocs.yml --strict
INFO    -  Cleaning site directory 
INFO    -  Building documentation to directory: /home/guts/Git/Geotribu/website/build/mkdocs/site 
INFO    -  Documentation built in 81.46 seconds

# quick check output
(.venv) guts:~/Git/Geotribu/website$ ls build/mkdocs/site/
404.html          articles  CNAME       dicogis               feed_rss_updated.xml  install_webapp        node  robots.txt  rss.xml  sitemap.xml     team   toc_nav_ignored
acknowledgements  assets    contribuer  feed_rss_created.xml  index.html            manifest.webmanifest  rdp   rss         search   sitemap.xml.gz  theme

# push on gh-pages
(.venv) guts:~/Git/Geotribu/website$ ghp-import --force --no-history --no-jekyll --push build/mkdocs/site
Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: Failed to rebase gh-pages branch.

I've also tried:

# using shell
$ ghp-import --force --no-history --no-jekyll --push --shell build/mkdocs/site
# no force
$ ghp-import --no-history --no-jekyll --push build/mkdocs/site

With the same error.

If I remove the --no-history option, it's working:

$ ghp-import --force --no-jekyll --push build/mkdocs/site
Énumération des objets: 1285, fait.
Décompte des objets: 100% (1285/1285), fait.
Compression par delta en utilisant jusqu'à 12 fils d'exécution
Compression des objets: 100% (55/55), fait.
Écriture des objets: 100% (649/649), 1.99 Mio | 3.25 Mio/s, fait.
Total 649 (delta 48), réutilisés 631 (delta 31), réutilisés du pack 0
remote: Resolving deltas: 100% (48/48), completed with 16 local objects.
To github.com:geotribu/website.git
   9ded7f3a4..e920821d5  gh-pages -> gh-pages

# checking
(.venv) guts:~/Git/Geotribu/website$ git log --branches="gh-p*"
commit e920821d5baaee83103faaf1ffe46e0d33438a56 (origin/gh-pages, gh-pages)
Author: Julien M. <[email protected]>
Date:   Thu Mar 25 12:06:18 2021 +0100

    Update documentation

commit 9ded7f3a473882ef56ab71e2b52beaaeca549cd5
Author: Julien M. (In Geo Veritas) <[email protected]>
Date:   Mon Mar 22 00:03:58 2021 +0100

    Update documentation

AND if I try again with --no-history, then it's working:

(.venv) guts:~/Git/Geotribu/website$ ghp-import --force --message="Deploy Geotribu static website" --no-history --no-jekyll --push build/mkdocs/site
Énumération des objets: 1205, fait.
Décompte des objets: 100% (1205/1205), fait.
Compression par delta en utilisant jusqu'à 12 fils d'exécution
Compression des objets: 100% (101/101), fait.
Écriture des objets: 100% (1205/1205), 5.02 Mio | 4.16 Mio/s, fait.
Total 1205 (delta 565), réutilisés 1164 (delta 539), réutilisés du pack 0
remote: Resolving deltas: 100% (565/565), done.
To github.com:geotribu/website.git
 + e920821d5...106a133dd gh-pages -> gh-pages (forced update)

 # checking
(.venv) guts:~/Git/Geotribu/website$ git log --branches="gh-p*"
commit 106a133ddcff615b7aa61fbe7a570fe26e828cf2 (origin/gh-pages, gh-pages)
Author: Julien M. <[email protected]>
Date:   Thu Mar 25 12:19:25 2021 +0100

    Deploy Geotribu static website

Am I missing something?

0.4.3 release?

Thanks much for ghp-import, I use it a lot.

I found myself trying to build some pages on Windows, and had to update to the latest master to get it to work. It did work fine from latest master though (ef30cbf). Any chance of a pypi release from latest master for us Windozers?

[question] Big Fat Warning

I've played with the tool (it's awesome!) and read the code, but haven't been able to figure out the exact cases in which users can loose their gh-pages branch, as warned in the README.

We plan on using ghp-import to deploy the website generated by Nikola, and would like to know, in what situations does the warning come true!

support utf-8 in messages with python 3.4

Hello,
I can't use accents in messages when using python3.4, however, it works in python2.7, here's a sample example:

ghp-import -m "Ajout article sur épreuve du bac" output/

Output:

fatal: Unsupported command: c
fast-import: dumping crash report to .git/fast_import_crash_10348
Traceback (most recent call last):
  File "/home/ben/.virtualenvs/py34/bin/ghp-import", line 12, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/ben/Documents/git/ghp-import/ghp-import", line 202, in <module>
    main()
  File "/home/ben/Documents/git/ghp-import/ghp-import", line 195, in main
    run_import(args[0], opts.branch, opts.mesg, opts.nojekyll)
  File "/home/ben/Documents/git/ghp-import/ghp-import", line 156, in run_import
    pipe.stdin.close()
BrokenPipeError: [Errno 32] Broken pipe

ghp-import: error: Unknown Git error

I'm trying to run the following

$ ghp-import -m "Commit Message" -b gh-pages output

But I get the error message below

Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: Unknown Git error

I'm using 0.5.0

check if content has changed

Thanks for ghp-import, this greatly simplifies update of the gh-pages branch!

The last thing I miss is a way to prevent ghp-import to commit and push if the output have not changed.
For example I'm using ghp-import in a post-commit hook to update the doc on every commit. So currently ghp-import push a new commit (often empty) to the gh-pages branch for every commits even those that don't change the output documentation.

Make it possible to use the tool inside Python

Hello, and thanks for the awesome tool!

As you have already seen in #26, the Nikola project will use ghp-import for its GitHub deploy feature. There might be one problem though, Python (and thus, ghp-import) is not always in the PATH. There is a way to change it: instead of installing ghp-import into /usr/bin or wherever it is on the system, install the script into /usr/lib/pythonX.Y/site-packages (or the usual virtualenv directory, or…) and put a small launcher script in /usr/bin. If distutils support is dropped, you can also leverage the usual entry_points mechanism and make things easier on Windows users in the process.

I can implement this if you agree.

Windows support

ghp_import.py -b test-branch .

File "python\3\scripts\ghp_import.py", line 207, in
main()
File "python\3\scripts\ghp_import.py", line 192, in main
check_repo(parser)
File "python\3\scripts\ghp_import.py", line 60, in check_repo
p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
File "python\3\lib\subprocess.py", line 950, in init
restore_signals, start_new_session)
File "python\3\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2]

This occured because of git cannot be resolved as git.exe or git.cmd according to %PATHEXT%.

It can be fixed by adding shell=True to Popen.

Non-Ascii character breaks setup py

The 'î' in "Benoît Chesneau" ala...

(py3)➜ ghp-import git:(master) python setup.py install    master
Traceback (most recent call last):
File "setup.py", line 9, in
LONG_DESC = open(os.path.join(os.path.dirname(file), "README.md")).read()
File "/Users/szabel/.virtualenvs/py3/bin/../lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1362: ordinal not in range(128)

Is it possible to ignore certain files?

I'm new to this project and am trying to find a way to have it ignore certain files and not upload them to the ghpages repository. My use case is that I have a couple large files (images or other) that I use locally, create lower resolution/quality versions, and use those in my pages. The high resolution versions can stick around so they don't have to be regenerated, but I don't need them uploaded.

Is any functionality like this available? Any ideas for how this could be implemented? I'd be willing to try.

expected "data- n" command, found...

I had used ghp-import successfully in windows, but no I swiched to linux an get the following error message when I run ghp-import docs:

fatal: Expected 'data n' command, found: 
fast-import: dumping crash report to .git/fast_import_crash_85004
Traceback (most recent call last):
  File "/home/nils/.local/bin/ghp-import", line 8, in <module>
    sys.exit(main())
  File "/home/nils/.local/lib/python3.8/site-packages/ghp_import.py", line 278, in main
    ghp_import(args[0], **opts.__dict__)
  File "/home/nils/.local/lib/python3.8/site-packages/ghp_import.py", line 257, in ghp_import
    run_import(git, srcdir, **opts)
  File "/home/nils/.local/lib/python3.8/site-packages/ghp_import.py", line 192, in run_import
    pipe.stdin.close()
BrokenPipeError: [Errno 32] Broken pipe

I dont even beginn to know how I could debug this, can you give me a hint?

Click to expand what the crash report says
      fast-import crash report:
        fast-import process: 85004
        parent process     : 85002
        at 2021-08-06 14:26:18 +0000
    
    fatal: Expected 'data n' command, found: 
    
    Most Recent Commands Before Crash
    ---------------------------------
      M 100644 inline mithelfen-anpacken-mithelfen/19-newsletter-abonnieren/index.html
      data 56612
      M 100644 inline mithelfen-anpacken-mithelfen/22-kontaktformular/index.html
      data 55895
      M 100644 inline mithelfen-anpacken-mithelfen/22-kontaktformular/1391103200_Blog_Artdesigner.lv.png
      data 15270
      M 100644 inline mithelfen-anpacken-mithelfen/75-teamtraining-mit-wiesel-co-am-zimmerb/Team_in_Aktion_WiCoZ.JPG
      data 138359
      M 100644 inline mithelfen-anpacken-mithelfen/75-teamtraining-mit-wiesel-co-am-zimmerb/index.html
      data 59495
      M 100644 inline mithelfen-anpacken-mithelfen/20-anpacken/index.html
      data 59136
      M 100644 inline site_libs/font-awesome-5.1.0/css/all.css
      data 45687
      M 100644 inline site_libs/font-awesome-5.1.0/css/v4-shims.css
      data 41293
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-brands-400.woff
      data 73920
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-brands-400.woff2
      data 63376
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-brands-400.ttf
      data 114816
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-regular-400.woff2
      data 14952
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-solid-900.woff
      data 76632
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-solid-900.woff2
      data 59572
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-regular-400.ttf
      data 40516
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-brands-400.svg
      data 622420
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-regular-400.eot
      data 40744
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-brands-400.eot
      data 115052
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-solid-900.eot
      data 160768
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-solid-900.svg
      data 592839
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-regular-400.svg
      data 141551
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-regular-400.woff
      data 18212
      M 100644 inline site_libs/font-awesome-5.1.0/webfonts/fa-solid-900.ttf
      data 160548
      M 100644 inline site_libs/lightable-0.0.1/lightable.css
      data 5090
      M 100644 inline site_libs/headroom-0.9.4/headroom.min.js
      data 5359
      M 100644 inline site_libs/popper-2.6.0/popper.min.js
      data 18453
      M 100644 inline site_libs/jquery-1.11.3/jquery.min.js
      data 95957
      M 100644 inline site_libs/webcomponents-2.0.0/webcomponents.js
      data 94086
      M 100644 inline site_libs/bowser-1.9.3/bowser.min.js
      data 7496
      M 100644 inline site_libs/tippy-6.2.7/tippy.umd.min.js
      data 22451
      M 100644 inline site_libs/tippy-6.2.7/tippy-light-border.css
      data 2810
      M 100644 inline site_libs/tippy-6.2.7/tippy.css````
      data 1390
      M 100644 inline site_libs/tippy-6.2.7/tippy-bundle.umd.min.js
      data 24077
      M 100644 inline site_libs/distill-2.2.21/template.v2.js
      data 143721
      M 100644 inline site_libs/fuse-6.4.1/fuse.min.js
      data 22858
      M 100644 inline site_libs/autocomplete-0.37.1/autocomplete.min.js
      data 57214
      M 100644 inline site_libs/header-attrs-2.8/header-attrs.js
      data 507
      M 100644 inline site_libs/kePrint-0.0.1/kePrint.js
      data 275
      M 100644 inline site_libs/anchor-4.2.2/anchor.min.js
      data 5827
      M 100644 inline wissenschaft-externe-projekte/wissenschaft-externe-projekte.json
      data 12542
      M 100644 inline wissenschaft-externe-projekte/131-nistkammer-monitoring/schema_Nistkammer-Monit-2.jpg
      data 50295
      M 100644 inline wissenschaft-externe-projekte/131-nistkammer-monitoring/index.html
      data 60240
      M 100644 inline wissenschaft-externe-projekte/131-nistkammer-monitoring/07260411-korr-hochf.jpg
      data 425484
      M 100644 inline wissenschaft-externe-projekte/90-stiftung-wieselnetz-win-wiesel-patchw/WIN_patchwork.png
      data 615619
      M 100644 inline wissenschaft-externe-projekte/90-stiftung-wieselnetz-win-wiesel-patchw/index.html
      data 59355
      M 100644 inline wissenschaft-externe-projekte/89-stiftung-wieselnetz-win-foerdermassna/index.html
      data 59107
      M 100644 inline wissenschaft-externe-projekte/89-stiftung-wieselnetz-win-foerdermassna/WIN_foerdermassnahmen.png
      data 434355
      M 100644 inline wissenschaft-externe-projekte/87-monitoring-der-kleinmusteliden-in-der/CSCF.png
      data 676999
      M 100644 inline wissenschaft-externe-projekte/87-monitoring-der-kleinmusteliden-in-der/index.html
      data 61249
      M 100644 inline wissenschaft-externe-projekte/126-mammaliabox/126-mammaliabox.Rmd
    * 
    
    Active Branch LRU
    -----------------
        active_branches = 1 cur, 5 max
    
      pos  clock name
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       1)      0 refs/heads/gh-pages
    
    Inactive Branches
    -----------------
    refs/heads/gh-pages:
      status      : active loaded dirty
      tip commit  : 75d11ffd69e0a8fcd46d1542dd7ea9e894dfbf6a
      old tree    : 0000000000000000000000000000000000000000
      cur tree    : 0000000000000000000000000000000000000000
      commit clock: 0
      last pack   : 
    
    
    Marks
    -----
    
    -------------------
    END OF CRASH REPORT

ImportError: cannot import name main

I am trying to use ghp-import.

I installed via pip: pip install ghp_import which gave the output

Collecting ghp_import
Installing collected packages: ghp-import
Successfully installed ghp-import-0.5.5

When I try to run the ghp-import script, I get the error

Traceback (most recent call last):
  File "/Users/rpa/anaconda/bin/ghp-import", line 7, in <module>
    from ghp_import import main
ImportError: cannot import name main

Versions of stuff:

$ python --version
Python 2.7.11 :: Anaconda 4.0.0 (x86_64)
$ pip --version
pip 9.0.1 from /Users/rpa/anaconda/lib/python2.7/site-packages (python 2.7)

I feel silly to be stuck on this, but I really can't get it to work. I also tried cloning the repo and running setup.py, but I got the same error.

Fails with "Not a git repository"

┌─[adam][Hapkido][/blog]
└─▪ pelican content -o output -s pelicanconf.py
WARNING: Empty alt attribute for image mimetex.cgi?G_%7B%5Calpha%20%5Cbeta%7D%20=%20T_%7B%5Calpha%20%5Cbeta%7D in /Users/adam/blog/content/new-direction.md
Done: Processed 32 article(s), 0 draft(s) and 0 page(s) in 0.90 seconds.
┌─[adam][Hapkido][
/blog]
└─▪ ghp-import output
Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: Not a git repository (or any of the parent directories): .git

The documentation indicated that the branch is created automatically?

http://docs.getpelican.com/en/3.5.0/tips.html

The output directory is a git repo:

┌─[adam][Hapkido][~/blog]
└─▪ ghp-import output
Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: Not a git repository (or any of the parent directories): .git

┌─[adam][Hapkido][/blog]
└─▪ cd output
┌─[adam][Hapkido][±][master ✗][
/blog/output]
└─▪ gs
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached ..." to unstage)

new file:   Test.html
new file:   archives.html
new file:   are-we-living-in-simulation.html

Problem installing ghp-import into Gradle project

I am using the gradle-use-python-plugin to try to install ghp-import into a Gradle project.

The project's build.gradle includes the following line:

python.pip 'ghp-import:1.0.0'

And when I run the plugin's pipList task, I see the following:

         Package         Version
	 --------------- -------
	 ghp-import      1.0.0
	 pip             20.2.4
	 python-dateutil 2.8.1
	 setuptools      50.3.2
	 six             1.15.0
	 wheel           0.35.1

So it looks like the install was successful.

However, if I try to run the ghp_import module, I get the following:

ModuleNotFoundError: No module named 'ghp_import'

The Python install in the project includes the following under site-packages:

ghp_import-1.0.0.dist.info
ghp_import.py

utf error

$ ./ghp-import public/
Traceback (most recent call last):
File "./ghp-import", line 178, in
main()
File "./ghp-import", line 171, in main
run_import(args[0], opts.branch, opts.mesg, opts.nojekyll)
File "./ghp-import", line 128, in run_import
add_file(pipe, fpath, gpath)
File "./ghp-import", line 100, in add_file
data = handle.read()
File "/usr/lib/python3.3/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 24: invalid continuation byte

What happens?

Problem adding file with CJK punctuation

Pelican uses ghp-import to publish blog articles to GitHub page, but I found it would throw out FileNotFoundError when the article used CJK punctuation because this method would change into ,.

I also found that this method is to solve this problem which already fixed by git. So I think we can remove this method.

Better support GithHub's user/org pages.

In addition to supporting project pages (which use the gh-pages branch of the same repo: username/projectname), GitHub also supports user/organization pages which use a separate repo at username/username.github.io which then is published at https://username.github.io (rather than https://username.github.io/projectname). The problem arises from the fact that user/org pages use the master branch, which requires the repo which holds the built pages to be different than the repo that ghp-import needs to publish to.

Consider the following pseudo workflow:

cd project
build_docs --docs docs/ --out site

At this point, I am in the project repo, not the pages repo. If I do an ghp-import call, I will be pushing to the wrong repo. So I tried setting up an extra remote:

git remote add pages https://github.com/username/username.github.io.git

Then if I run:

ghp-import -r pages -b master site

It pushes the contents of the site dir to the master branch of the pages repo and my site gets published. However, in the process it also skunks my project repo by adding the same commit to the master branch of the local repo.

Perhaps if there was an option to specify a local branch to use, that would resolve the issue:

ghp-import -r pages -b master --local-branch foo site

Then the commit would be committed to the foo branch (or whatever I choose to call it), which would then get pushed to the master branch of the pages remote.

I realize that a workaround exists today, by changing to the pages branch and then calling ghp-import, but I'd rather not have to do this:

cd ../pages-repo
ghp-import -r origin -b master ../project/site

Option to preserve symlinks

Git supports symbolic links and symbolic links work with GitHub Pages (see example).

Currently, the default behavior of ghp-import is to follow symlinks for files but not directories. Specifying --follow-links causes ghp-import to follow links for both files and directories: see #37 (comment). However, neither case preserves the symlinks, which is a feature that would help me with manubot/rootstock#101.

Perhaps the ideal behavior (disregarding backwards compatibility) would be to:

  • preserve symlinks that link to a file or directory within the "documentation directory"
  • follow symlinks that link to a file or directory outside of the "documentation directory"

However, given backwards compatibility, it would make sense perhaps to have a --preserve-links argument that would preserve all symbolic links. It would be mutually exclusive with --follow-links.

@davisp what do you think? I could try to take a crack at an implementation. I haven't looked much into how difficult this would be to implement.

Bug?

Using Python 3.5.2 and ghp-import version 0.5, running ghp-import _build/singlehtml/ gives me the following error.

  File "/Users/bingo/.virtualenvs/vegehead/bin/ghp-import", line 11, in <module>
    sys.exit(main())
  File "/Users/bingo/.virtualenvs/vegehead/lib/python3.5/site-packages/ghp_import.py", line 192, in main
    check_repo(parser)
  File "/Users/bingo/.virtualenvs/vegehead/lib/python3.5/site-packages/ghp_import.py", line 65, in check_repo
    error = error.decode("utf-8")
AttributeError: 'str' object has no attribute 'decode'

raw date crash

Hi

does anyone get a invalid raw date error
2017-01-23 13_28_18-output

i have no idea how to fix that

Add a --no-history optin to avoid growing branch weight

Hi there,

First of all, thanks for you tool. It's really useful and easy to use.

As a new feature, I would suggest to add a --no-history option.

Deploying regularly to the branch gh-pages make its the git history growing again and again. But this branch (or any branch used to host static content) doesn't really need to be versioned into the history.

There is a similar tool written in nodejs which has an option --no-history to overwrite the previous commit: gh-pages. It's reported that it works well, as it in a GH Action.

- name: deploy to gh pages
  run: |
    echo "Deploying to directory: ${{env.BRANCH_NAME}}"
    git config --global user.name "github-actions[bot]"
    git config --global user.email "github-actions[bot]@users.noreply.github.com"
    npx gh-pages --dist dist/ --dest ${{env.BRANCH_NAME}} --remove "${{env.BRANCH_NAME}}/**" --no-history --repo "https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git"

NPM option: https://www.npmjs.com/package/gh-pages#optionshistory

Original issue: geotribu/website#302 by @fgravin

find_repo/is_repo does not respect GIT_DIR

ghp-import does not respect the GIT_DIR environment variable, which means that ghp-import has to be ran from the git repository. This is fine for most situations, but isn't vary handy for post-receive hooks.

-m probably doesn't work well with non-ascii

#!/bin/bash
SITENAME="Pražení"
ghp-import -m "$SITENAME :notebook_with_decorative_cover:" ./content

...results in...

fatal: Unsupported command: r:
fast-import: dumping crash report to .git/fast_import_crash_5421
Traceback (most recent call last):
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 30, in write
    pipe.stdin.write(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 198, in <module>
    main()
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 191, in main
    run_import(args[0], opts.branch, opts.mesg, opts.nojekyll)
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 148, in run_import
    add_file(pipe, fpath, gpath)
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 121, in add_file
    write(pipe, enc(data))
  File "/Users/honzajavorek/Workspace/prazeni/env/bin/ghp-import", line 32, in write
    if e.errno != errno.EPIPE:
NameError: name 'errno' is not defined
^Cmake: *** [deploy] Interrupt: 2

Allow symlinks in gh-pages

For a strange use case, we have a gh-pages directory that requires a symlink. The symlink is fine in the build directory, but never comes across when using gh-pages.

In my quick read of the code, I can't see anything obvious that would allow us to bring symlinks across. It would be great if this could be supported

ghp-import with two users?

I don't think this is an issue with ghp-import, but I want to know if there is preferred workflow for collaborators updating a github-pages site:

Use case:

  1. I use ghp-import -n -f -p _build/html to send updated html to github-pages
  2. Collaborator updates source files and builds html
  3. Collaborator uses ghp-import -n -f -p _build/html, but receives error

Is there a better workflow?

fatal: Invalid raw date

Hi, thanks for the repository.

I installed via pip: pip install ghp_import without problems

However, when running ghp-import -n -p -f _build/html/within my git repository I got:

fatal: Invalid raw date "<<XXX>> 1593556860 +0100" in ident:  <XXX> <<XXX>> 1593556860 +0100
fast-import: dumping crash report to .git/fast_import_crash_49369
Traceback (most recent call last):
  File "/Users/XXX/miniconda3/envs/AOS/bin/ghp-import", line 8, in <module>
    sys.exit(main())
  File "/Users/XXX/miniconda3/envs/AOS/lib/python3.8/site-packages/ghp_import.py", line 238, in main
    run_import(git, args[0], opts)
  File "/Users/XXX/miniconda3/envs/AOS/lib/python3.8/site-packages/ghp_import.py", line 185, in run_import
    pipe.stdin.close()
BrokenPipeError: [Errno 32] Broken pipe

I am using Python 3.8.3 and conda 4.8.3

any help?

thanks!.

Git author and committer environment variables are not respected

The following git environment variables do not appear to be respected by ghp-import:

  • GIT_AUTHOR_NAME
  • GIT_AUTHOR_EMAIL
  • GIT_COMMITTER_NAME
  • GIT_COMMITTER_EMAIL

Probably more are not respected, but these are the ones I observed in my own environment after switching from ~/.gitconfig to environment variables. When I re-enabled these configurations in ~/.gitconfig and ran a test ghp-import -p -r github -b gh-pages docs the commit information was available in the new commit.

I attempted to run ghp-import -s but experienced the behaviors from #63.

This bug was originally posted to mkdocs, but was found to be caused by ghp-import.

Execute on shell to recoginze

I tried executing ghp-import and it works great without -s command.

The command I executed is like this

ghp-import -c 'mysubdomain.domain.com' -m 'Deployed via ghp-import' -p -b 'gh-pages' ./docs/

But because I've set up git to sign commit + bunch of step to make it automatically sign every time you commit via git commit so you don't have to enter password every time. These workflow is not recognized anymore if execute with command above, ...

thus I tried with -s option as I think it will take all setup in ~/.bash_profile and shell environment into effect but with no luck. I always get the following error

ghp-import -c 'mysubdomain.domain.com' -m 'Deployed via ghp-import' -p -b 'gh-pages' -s ./docs/
Usage: ghp-import [OPTIONS] DIRECTORY

ghp-import: error: Unknown Git error

The command executed is same as the first one except that it has -s at the end before directory parameter.

I could verify whether it's successful or not, by taking a look at commit in which it should have verified tagged along side on Github website. The command without -s successfully committed but with no verified tag. On side note, mkdocs also behaves the same with no verfiied tag. Any idea to solve this issue?

Popen.communte() returns bytes. Str expected

Probably fixed... Under Python 3.4.2, Win8.1 it broke with:

Traceback (most recent call last):
  File "C:\python\Scripts\ghp-import", line 198, in <module>
    main()
  File "C:\python\Scripts\ghp-import", line 188, in main
    if not try_rebase(opts.remote, opts.branch):
  File "C:\python\Scripts\ghp-import", line 77, in try_rebase
    if sp.call(cmd) != 0:
  File "C:\PYTHON\lib\subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\PYTHON\lib\subprocess.py", line 858, in __init__
    restore_signals, start_new_session)
  File "C:\PYTHON\lib\subprocess.py", line 1085, in _execute_child
    args = list2cmdline(args)
  File "C:\PYTHON\lib\subprocess.py", line 663, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: Type str doesn't support the buffer API

In short it expects str but bytes supplied in rev at ghp-import:73:

(rev, ignore) = p.communicate() 

The git rev-list --max-count=1 origin/gh-pages returns b'ca1ef5c5a8b95b55d2b5c2897ad0a378e29fc724'.

fatal error when using GIT_DIR

Try using ghp-import to push a folder with pages from another folder containing pages source. I'm using a basic script to call ghp-import with a var

#!/bin/sh
export GIT_DIR=`pwd`"/JSteunou.github.io"
ghp-import -b master -p $1

but I got this

./ghp.sh /home/g-rom/Git/jeromesteunou.net/output
fatal: Not a git repository: '/home/g-rom/Git/jeromesteunou.net/JSteunou.github.io'
Traceback (most recent call last):
  File "/home/g-rom/.virtualenvs/jeromesteunou.net/bin/ghp-import", line 197, in <module>
    main()
  File "/home/g-rom/.virtualenvs/jeromesteunou.net/bin/ghp-import", line 190, in main
    run_import(args[0], opts.branch, opts.mesg, opts.nojekyll)
  File "/home/g-rom/.virtualenvs/jeromesteunou.net/bin/ghp-import", line 137, in run_import
    start_commit(pipe, branch, message)
  File "/home/g-rom/.virtualenvs/jeromesteunou.net/bin/ghp-import", line 102, in start_commit
    write(pipe, enc('commit refs/heads/%s\n' % branch))
  File "/home/g-rom/.virtualenvs/jeromesteunou.net/bin/ghp-import", line 35, in write
    pipe.stdin.write(data)
IOError: [Errno 32] Broken pipe
make: *** [github] Erreur 1

I tested my path to be sure by copy paste "/home/g-rom/Git/jeromesteunou.net/JSteunou.github.io" and doing git status: all fine.

I managed it by changing my shell script to drop the use of GIT_DIR and move into the directory before launching ghp-import, but I would to know if I'm using GIT_DIR the wrong way or if it's a bug.

ghp-import error on Windows 10

I am trying to run this command _ghp-import output -b master_to import everything in my output folder to master branch. However, I keep getting errors that says:

'ghp-import' is not recognized as an internal or external command, operable program or batch file.

I have tried out solutions in previous posts but it is not working for me.

skip deploy if no update

Add an option e.g. --if-changes so that if the only thing which changes is the build timestamp comment in index.html, mkdocs gh-deploy should do nothing.

So far my workaround is:

mkdocs build
git fetch origin gh-pages:gh-pages
ghp-import site
[[ "$(git diff origin/gh-pages..gh-pages --numstat | grep -v sitemap.xml.gz)" != 1$'\t'1$'\t'index.html ]] \
  && git push -f origin gh-pages

this should fix #2

errno is used but not imported

My text editor highlights flake8 warnings, which made me notice this. On line 32 of ghp-import you have a condition

            if e.errno != errno.EPIPE:

but the errno module is not imported.

Allow deployment to a specific folder, keeping others

I'd like to be able to have docs for several branches concurrently. For example, I want /master/ to have docs for the master branch, /dev/ to have docs for the dev branch and so on. It would be great if there was an option to deploy a specific folder, leaving others untouched.

Clobbers custom domain

After publishing, the Github Pages "Custom Domain" repository setting is blanked out.

ghp-import: python: bad interpreter: No such file or directory

I tried pelican and used the command make github on python 3.5 and i got this error.
On python2.7 is everything fine.

~/p/t/timkl.xyz (content) $ make github
pelican /home/tim/projects/timkl.xyz/timkl.xyz/content -o /home/tim/projects/timkl.xyz/timkl.xyz/output -s /home/tim/projects/timkl.xyz/timkl.xyz/publishconf.py 
Done: Processed 11 articles, 0 drafts, 0 pages and 0 hidden pages in 0.31 seconds.
ghp-import -m "Generate Pelican site" -b master /home/tim/projects/timkl.xyz/timkl.xyz/output
/bin/sh: /home/tim/.virtualenvs/pelican/bin/ghp-import: python: bad interpreter: No such file or directory

I found this related to my problem but it didn't help me.
getpelican/pelican#1274

Missing Github Tags for Releases

It looks like releases have been pushed to pypi but no tags have been uploaded here. Can we get the tags pushed here as well by chance?

Timezone calculation logic in ghp-import is incorrect

The logic used is

currtz = "%+05d" % (-1 * time.timezone / 36) # / 3600 * 100

For my timezone IST (+0530), time.timezone returns -19800 which should translate to 5 hours 30 minutes. But the above code calculates it as +0550. This sets the timezone incorrectly in the commits created by ghp-import

Does not run when called from shell in Windows 7

Calling ghp-import from cmd does not work on Windows 7 by default. Windows was having trouble recognizing the script as executable. I went into /Scripts and changed ghp-import's extension to .py, and that fixed things. How do I go about fixing this in the repository in general? Is the solution to tack .py to the end of the file name?

Fails when git config user.name contains non-ascii characters

When trying to use it, I get an error:

Traceback (most recent call last):
  File "C:\Python27\Scripts\ghp-import-script.py", line 9, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python27\lib\site-packages\ghp_import.py", line 238, in main
    run_import(git, args[0], opts)
  File "c:\python27\lib\site-packages\ghp_import.py", line 173, in run_import
    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python27\lib\site-packages\ghp_import.py", line 128, in start_commit
    write(pipe, enc('committer %s <%s> %s\n' % (uname, email, mk_when())))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 11: ordinal not in range(128)

my user.name=Rafał Michalski if I replace utf-8 ł with ascii l it works.

use with Circle-CI

Deploying from Circle-CI seems to work only when using https rather than ssh.

For example, this commit openworm/openworm_docs@00f498c breaks deployment despite having a GitHub ssh user key with read/write access (https://circleci.com/docs/2.0/gh-bb-integration/#deployment-keys-and-user-keys) and no default (read only) deploy key

From mkdocs/mkdocs#1898 this appears to be a ghp-import issue rather than mkdocs.

The error message also must be wrong:

from https://circleci.com/gh/openworm/openworm_docs/598:

git fetch origin gh-pages:gh-pages
ghp-import site
git push origin gh-pages

produces:

 * [new branch]      gh-pages   -> gh-pages
ERROR: Permission to openworm/openworm_docs.git denied to openworm-bot.
fatal: Could not read from remote repository.

so clearly the fetch works, implying "Could not read from remote repository" should at least be "Could not write to remote repository"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.