Version 2 (modified by Aymeric Augustin, 9 years ago) (diff)


This page is an unofficial list of tips that may be useful for committers and other contributors to Django.

Automating Backports

Backporting can be tedious. The following script makes it a bit easier by performing the git cherry-pick and modifying the commit message by prepending the branch name and appending "Backport of XXXXXXXX from master.".

Put the contents below in django-src/ Add to django-src/.git/info/exclude to prevent the file from appearing in git status.

After committing a change to master. Switch to the branch you wish to backport to and execute ./backport <hash of commit to backport>. You can double check the commit message looks ok, then git push.

BRANCH_NAME=`git branch | sed -n '/\* stable\//s///p'`

git reset --hard

: ${ORIGBRANCH=master}


# Cherry-pick the other commit
#ORIGID=`git find-rev r${REV} ${ORIGBRANCH}`
#if [ -z "${ORIGID}" ] ; then
#    echo "Revision ${REV} not found in branch ${ORIGBRANCH}"
#    exit 1
git cherry-pick ${REV}

# Create new log message by modifying the old one
git log --pretty=format:"[${BRANCH_NAME}] %s%n%n%b%nBackport of ${REV:0:10} from master" HEAD^..HEAD \
    | grep -v '^BP$' > ${TMPFILE}

# Commit new log message
git commit --amend -F ${TMPFILE}

# Clean up temporary files
rm -f ${TMPFILE}

Deleting empty directories and pyc files

When switching branches, it's useful to delete directories that don't exist on the branch you're switching to, as well as pyc files so that state from one branch doesn't persist on the new one. Put the following contents in django-src/.git/hooks/post-checkout and ensure the file is executable (chmod +x django-src/.git/hooks/post-checkout).

#! /bin/sh

# Start from the repository root.
cd ./$(git rev-parse --show-cdup)

# Delete .pyc files and empty directories.
find . -name "*.pyc" -delete
find . -type d -empty -delete

Running tests

Use the djangocore-box VM to easily run the Django test suite using different Python versions and different database backends.

Applying patches from Trac or GitHub will automatically look for the latest patch attached to a ticket, or failing that, for the latest pull request mentioned in the comment, and apply it to your local checkout.

Back to Top