c-w / ghp-import

Easily import docs to your gh-pages branch.
https://pypi.org/project/ghp-import/
Apache License 2.0
604 stars 79 forks source link

Alternative to --no-history #126

Open framillien opened 9 months ago

framillien commented 9 months ago

I use ghp-import with a variable prefix, to keep a disctinct doc folder by release and one for all nightly updates, like:

# version = 'latest' or a semver version
ghp-import --prefix=${version}  -m 'Update ${version}' --push doxygen_html

As you expect, without --no-history this repo growth out of control, but I need to keep data for each releases. I end up with a git-filter to squash commits from nightly builds, like:

ghp-import --prefix=${version} -m 'Update ${version}' doxygen_html
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --commit-filter '
    if [ "$(git rev-parse gh-pages)" != "$GIT_COMMIT" ] && [ $(git show -s --format=%B "$GIT_COMMIT" | grep -c "Update latest") -gt 0 ]
    then
        skip_commit "$@";
    else
        git commit-tree "$@";
    fi' gh-pages
git push origin +gh-pages

This command merge all commits with a common commit message the result is:

I wonder if this kind of commit squash command could be added to ghp-import as an alternative to --no-history. In the simplest form we can squash all commits of the branch without bother about commit message, or we can try to keep some ways to choose which commits should be squashed.

Could be:

-a, --squash-history      Squash commits, keeping data. If --message param
                          is set, filtering squashed commits on this commit
                          message, else squash all commits in the branch.
                          Act like `--no-history` but without discarding data.

ghp-import --prefix=${version}  -m 'Update ${version}' --push --squash-history doxygen_html

Note: -a to keep -q for potential --quiet parameter.

framillien commented 9 months ago

This git-filter command can be tested with:

mkdir git-playground && cd git-playground
git init
touch a && git add a && git commit -m "initial"
git branch gh-pages && git checkout gh-pages
touch test1 && git add test1 && git commit -m "Update latest"
touch test2 && git add test2 && git commit -m "Update latest"
touch test3 && git add test3 && git commit -m "Update v1.0.0"
touch test4 && git add test4 && git commit -m "Update latest"
git checkout master
c-w commented 9 months ago

Sounds good, feel free to open a pull request for this. Thanks!

framillien commented 9 months ago

Let's go ! We continue discussion here or on the PR ?

framillien commented 9 months ago

Hi, the PR should be in an reviewable state now, still some open subjects about stdout messages, should we add warning about potential missing tools on Windows (grep), ...

I also see that the pipeline become obsolete due to Python 2.7 checks, is it something you want to change ? Updating the min Python supported version to a 3.X.