2021-10-07 13:20:08 +09:00
# Contribution Workflow
2021-10-06 12:53:54 +09:00
Much of the workflow for contributing to CodeIgniter (or any project)
involves understanding how [Git ](https://git-scm.com/ ) is used to manage
a shared repository and contributions to it. Examples below use the Git
bash shell, to be as platform neutral as possible. Your IDE may make
some of these easier.
Some conventions used below, which you will need to provide appropriate
values for when you try these:
ALL_PROJECTS // folder location with all your projects in subfolders, eg /lampp/htdocs
YOUR_PROJECT // folder containing the project you are working on, inside ALL_PROJECTS
ORIGIN_URL // the cloning URL for your repository fork
UPSTREAM_URL // the cloning URL for the CodeIgniter4 repository
2021-10-07 13:20:08 +09:00
## Branching
2021-10-06 12:53:54 +09:00
2022-06-17 12:09:39 +09:00
- All bug fix PRs should be sent to the __ "develop"__ branch, this is where the next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __ "4.3"__
The "master" branch will always contain the latest stable
2021-10-06 12:53:54 +09:00
version and is kept clean so a "hotfix" (e.g: an emergency security
patch) can be applied to master to create a new version, without
2022-06-17 12:09:39 +09:00
worrying about other features holding it up. Any sent to "master" will be
closed automatically.
If you have multiple changes to submit, please
2021-10-06 12:53:54 +09:00
place each change into their own branch on your fork.
One thing at a time: a pull request should only contain one change. That
does not mean only one commit, but one change - however many commits it
took. The reason for this is that if you change X and Y but send a
single pull request for both at the same time, we might really want X
but disagree with Y, meaning we cannot merge the request. Using the
Git-Flow branching model you can create new branches for both of these
features and send two requests.
2021-10-07 13:20:08 +09:00
## Forking
2021-10-06 12:53:54 +09:00
You work with a fork of the CodeIgniter4 repository. This is a copy of
2021-10-07 12:31:48 +09:00
our repository, in your GitHub account. You can make changes to your
2021-10-06 12:53:54 +09:00
forked repository, while you cannot do the same with the shared one -
you have to submit pull requests to it instead.
[Creating a fork ](https://help.github.com/articles/fork-a-repo/ ) is done
2021-10-07 10:19:51 +09:00
through the GitHub website. Navigate to [our
2021-10-06 12:53:54 +09:00
repository](https://github.com/codeigniter4/CodeIgniter4), click the
**Fork** button in the top-right of the page, and choose which account
or organization of yours should contain that fork.
2021-10-07 13:20:08 +09:00
## Cloning
2021-10-06 12:53:54 +09:00
2021-10-07 10:19:51 +09:00
You *could* work on your repository using GitHub's web interface, but
2021-10-06 12:53:54 +09:00
that is awkward. Most developers will clone their repository to their
local system, and work with it there.
2021-10-07 10:19:51 +09:00
On GitHub, navigate to your forked repository, click **Clone or
2021-10-06 12:53:54 +09:00
download**, and copy the cloning URL shown. We will refer to this as
ORIGIN\_URL.
Clone your repository, leaving a local folder for you to work with:
2022-07-02 08:14:10 +09:00
```console
> cd ALL_PROJECTS
> git clone ORIGIN_URL
```
2021-10-06 12:53:54 +09:00
2022-06-17 12:09:39 +09:00
## Syncing your repository
2021-10-06 12:53:54 +09:00
Within your local repository, Git will have created an alias,
2021-10-07 10:19:51 +09:00
**origin**, for the GitHub repository it is bound to. You want to create
2021-10-06 12:53:54 +09:00
an alias for the shared repository as well, so that you can "synch" the
two, making sure that your repository includes any other contributions
that have been merged by us into the shared repo:
2022-07-02 08:14:10 +09:00
```console
> git remote add upstream UPSTREAM_URL
```
2021-10-06 12:53:54 +09:00
Then synchronizing is done by pulling from us and pushing to you. This
is normally done locally, so that you can resolve any merge conflicts.
For instance, to synchronize **develop** branches:
2022-07-02 08:14:10 +09:00
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```
2021-10-06 12:53:54 +09:00
2021-10-07 12:47:57 +09:00
You might get merge conflicts when you merge. It is your
2021-10-06 12:53:54 +09:00
responsibility to resolve those locally, so that you can continue
collaborating with the shared repository. Basically, the shared
repository is updated in the order that contributions are merged into
it, not in the order that they might have been submitted. If two PRs
update the same piece of code, then the first one to be merged will take
precedence, even if it causes problems for other contributions.
It is a good idea to synchronize repositories when the shared one
changes.
2021-10-07 13:20:08 +09:00
## Branching Revisited
2021-10-06 12:53:54 +09:00
The top of this page talked about the **master** and **develop**
branches. The *best practice* for your work is to create a *feature
branch* locally, to hold a group of related changes (source, unit
2021-10-07 19:22:46 +09:00
testing, documentation, changelog, etc).
2021-10-06 12:53:54 +09:00
This local branch should be named appropriately, for instance
"fix/problem123" or "new/mind-reader". The slashes in these branch names
is optional, and implies a sort of namespacing if used.
2022-07-02 08:09:35 +09:00
- All bug fix PRs should be sent to the __ "develop"__ branch, this is where the next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __ "4.3"__
For instance, if you send a PR to __ "develop"__ branch, make sure you are in the *develop* branch, and create a
new bugfix branch, based on *develop* , for a new feature you are
2021-10-06 12:53:54 +09:00
creating:
2022-07-02 08:14:10 +09:00
```console
> git switch develop
> git switch -c fix/problem123
```
2022-07-02 08:09:35 +09:00
If you send a PR with an enhancement, make sure you are in the *next minor version* branch,
and create a new feature branch, based on, e.g., *4.3* , for a new feature you are creating:
2022-07-02 08:14:10 +09:00
```console
> git switch 4.3
> git switch -c new/mind-reader
```
2021-10-06 12:53:54 +09:00
Saving changes only updates your local working area.
2021-10-07 13:20:08 +09:00
## Committing
2021-10-06 12:53:54 +09:00
Your local changes need to be *committed* to save them in your local
repository. This is where [contribution signing ](./signing.md ) comes
in.
You can have as many commits in a branch as you need to "get it right".
For instance, to commit your work from a debugging session:
2022-07-02 08:14:10 +09:00
```console
> git add .
> git commit -S -m "Find and fix the broken reference problem"
```
2021-10-06 12:53:54 +09:00
Just make sure that your commits in a feature branch are all related.
If you are working on two features at a time, then you will want to
switch between them to keep the contributions separate. For instance:
2022-07-02 08:14:10 +09:00
```console
> git switch new/mind-reader
> ## work away
> git add .
> git commit -S -m "Added adapter for abc"
> git switch fix/issue-123
> ## work away
> git add .
> git commit -S -m "Fixed problem in DEF\Something"
> git switch develop
```
2021-10-06 12:53:54 +09:00
The last checkout makes sure that you end up in your *develop* branch as
a starting point for your next session working with your repository.
This is a good practice, as it is not always obvious which branch you
are working in.
2021-10-07 13:20:08 +09:00
## Pushing Your Branch
2021-10-06 12:53:54 +09:00
At some point, you will decide that your feature branch is complete, or
that it could benefit from a review by fellow developers.
**Note:**
2021-10-07 12:47:41 +09:00
> Remember to sync your local repo with the shared one before pushing!
2021-10-06 12:53:54 +09:00
It is a lot easier to resolve conflicts at this stage.
Synchronize your repository:
2022-07-02 08:14:10 +09:00
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```
2021-10-06 12:53:54 +09:00
Bring your feature branch up to date:
2022-07-02 08:14:10 +09:00
```console
2022-07-02 08:15:09 +09:00
> git switch fix/issue-123
2022-07-02 08:14:10 +09:00
> git rebase upstream/develop
```
2021-10-06 12:53:54 +09:00
2021-10-07 12:31:48 +09:00
And finally push your local branch to your GitHub repository:
2021-10-06 12:53:54 +09:00
2022-07-02 08:14:10 +09:00
```console
2022-07-02 08:15:09 +09:00
> git push --force-with-lease origin fix/issue-123
2022-07-02 08:14:10 +09:00
```
2021-10-06 12:53:54 +09:00
2021-10-07 13:20:08 +09:00
## Pull Requests
2021-10-06 12:53:54 +09:00
2021-10-07 10:19:51 +09:00
On GitHub, you propose your changes one feature branch at a time, by
2021-10-06 12:53:54 +09:00
switching to the branch you wish to contribute, and then clicking on
"New pull request".
2022-06-17 12:09:39 +09:00
Make sure the pull request is for the shared __ "develop"__ or next minor version branch, e.g. __ "4.3"__, or it
2021-10-06 12:53:54 +09:00
may be rejected.
Make sure that the PR title is helpful for the maintainers and other
developers. Add any comments appropriate, for instance asking for
review.
2021-10-07 11:44:13 +09:00
**Note:**
> If you do not provide a title or description for your PR, the odds of it being summarily rejected
rise astronomically.
2021-10-06 12:53:54 +09:00
When your PR is submitted, a continuous integration task will be
triggered, running all the unit tests as well as any other checking we
have configured for it. If the unit tests fail, or if there are merge
conflicts, your PR will not be mergeable until those are fixed.
Fix such changes locally, commit them properly, and then push your
branch again. That will update the PR automatically, and re-run the CI
tests. You don't need to raise a new PR.
If your PR does not follow our contribution guidelines, or is
incomplete, the codebase maintainers will comment on it, pointing out
what needs fixing.
2021-11-10 10:23:16 +09:00
### Labeling PRs
If you have the privilege of labeling PRs, you can help the maintainers.
Label your PRs with the one of the following [labels ](https://github.com/codeigniter4/CodeIgniter4/labels ):
- **bug** ... PRs that fix bugs
- **enhancement** ... PRs to improve existing functionalities
- **new feature** ... PRs for new features
- **refactor** ... PRs to refactor
And if your PRs have the breaking changes, label the following label:
- **breaking change** ... PRs that may break existing functionalities
2022-05-30 05:48:43 +09:00
## Updating Your Branch
If you are asked for changes in the review, commit the fix in your branch and push it to GitHub again.
2022-06-17 12:09:39 +09:00
If the __ "develop"__ or next minor version branch, e.g. __ "4.3"__, progresses and conflicts arise that prevent merging, or if you are asked to *rebase* ,
2022-05-30 05:48:43 +09:00
do the following:
Synchronize your repository:
2022-07-02 08:14:10 +09:00
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```
2022-05-30 05:48:43 +09:00
Bring your feature branch up to date:
2022-07-02 08:14:10 +09:00
```console
2022-07-02 08:15:09 +09:00
> git switch fix/problem123
2022-07-02 08:14:10 +09:00
> git rebase upstream/develop
```
2022-05-30 05:48:43 +09:00
You might get conflicts when you rebase. It is your
responsibility to resolve those locally, so that you can continue
collaborating with the shared repository.
And finally push your local branch to your GitHub repository:
2022-07-02 08:14:10 +09:00
```console
2022-07-02 08:15:09 +09:00
> git push --force-with-lease origin fix/problem123
2022-07-02 08:14:10 +09:00
```
2022-05-30 05:48:43 +09:00
2022-08-13 07:49:56 +09:00
## If you sent to the wrong branch
If you have sent a PR to the wrong branch, you need to create a new PR branch.
When you have the PR branch `feat-abc` and you should have sent the PR to `4.3` ,
but you created the PR branch from `develop` and sent a PR.
Update your `4.3` branch:
```console
> git switch 4.3
> git fetch upstream
> git merge upstream/4.3
> git push origin 4.3
```
Create a new branch `feat-ab.new` from the correct branch `4.3` :
```console
> git switch -c feat-abc.new 4.3
```
Cherry-pick the commits you did:
```console
> git cherry-pick <commit_id> <commit_id> <commit_id> ...
```
Rename the PR branch `feat-abc` :
```console
> git branch -m feat-abc feat-abc.old
```
Rename the new branch `feat-abc.new` to `feat-abc` .
```console
> git branch -m feat-abc.new feat-abc
```
Force push.
```console
> git push --force-with-lease origin feat-abc
```
On the GitHub PR page, change the base branch to the correct branch `4.3` .
2021-10-07 13:20:08 +09:00
## Cleanup
2021-10-06 12:53:54 +09:00
If your PR is accepted and merged into the shared repository, you can
2021-10-07 12:31:48 +09:00
delete that branch in your GitHub repository as well as locally.