Skip to content

Latest commit

 

History

History
236 lines (157 loc) · 10.1 KB

git-workflow.md

File metadata and controls

236 lines (157 loc) · 10.1 KB

Git 的工作流程 - 贡献 iiSNS 代码

你想参与到 iiSNS 的开发?很好!但为了能让你快速上手,请遵循以下步骤。 如果你是一个 Git 新手,对 GitHub 不熟悉,你应首先要查看 GitHub 帮助, 使用 Git 或者学习其它关于 Git internal data model

准备你的开发环境

以下步骤将为 iiSNS 创建一个开发环境,这将让你使用 iiSNS 来工作,在你贡献代码之前应先完成这些步骤。

1. Fork the iiSNS repository on GitHub and clone your fork to your development environment

git clone [email protected]:YOUR-GITHUB-USERNAME/iisns.git

If you have trouble setting up Git with GitHub in Linux, or are getting errors like "Permission Denied (publickey)", then you must setup your Git installation to work with GitHub

2. Add the main iiSNS repository as an additional git remote called "upstream"

Change to the directory where you cloned iiSNS, normally, "iisns". Then enter the following command:

git remote add upstream git://github.com/shi-yang/iisns.git

3. Prepare the testing environment

The following steps are not necessary if you want to work only on translations or documentation.

Note: If you see errors like Problem 1 The requested package bower-asset/jquery could not be found in any version, there may be a typo in the package name., you will need to run composer global require "fxp/composer-asset-plugin:1.0.0"

  • run php build/build dev/app basic to clone the basic app and install composer dependencies for the basic app. This command will install foreign composer packages as normal but will link the iisns repo to the currently checked out repo, so you have one instance of all the code installed.

    Do the same for the advanced app if needed: php build/build dev/app advanced.

    This command will also be used to update dependencies, it runs composer update internally.

Note: The default git repository Urls clone from github via SSH, you may add the --useHttp flag to the build command to use HTTPs instead.

Now you have a working playground for hacking on iiSNS

The following steps are optional.

Unit tests

You can execute unit tests by running phpunit in the repo root directory. If you do not have phpunit installed globally you can run php vendor/bin/phpunit instead.

Some tests require additional databases to be set up and configured. You can create tests/data/config.local.php to override settings that are configured in tests/data/config.php.

You may limit the tests to a group of tests you are working on e.g. to run only tests for the validators and redis phpunit --group=validators,redis. You get the list of available groups by running phpunit --list-groups.

Extensions

To work on extensions you have to clone the extension repository. We have created a command that can do this for you:

php build/build dev/ext <extension-name>

where <extension-name> is the name of the extension, e.g. redis.

If you want to test the extension in one of the application templates, just add it to the composer.json of the application as you would normally do e.g. add "yiisoft/iisns-redis": "*" to the require section of the basic app. Running php build/build dev/app basic will install the extension and its dependecies and create a symlink to extensions/redis so you are not working in the composer vendor dir but in the iisns repository directly.

Note: The default git repository Urls clone from github via SSH, you may add the --useHttp flag to the build command to use HTTPs instead.

Working on bugs and features

Having prepared your develop environment as explained above you can now start working on the feature or bugfix.

1. Make sure there is an issue created for the thing you are working on if it requires significant effort to fix

All new features and bug fixes should have an associated issue to provide a single point of reference for discussion and documentation. Take a few minutes to look through the existing issue list for one that matches the contribution you intend to make. If you find one already on the issue list, then please leave a comment on that issue indicating you intend to work on that item. If you do not find an existing issue matching what you intend to work on, please open a new issue or create a pull request directly if it is straightforward fix. This will allow the team to review your suggestion, and provide appropriate feedback along the way.

For small changes or documentation issues or straightforward fixes, you don't need to create an issue, a pull request is enough in this case.

2. Fetch the latest code from the main iiSNS branch

git fetch upstream

You should start at this point for every new contribution to make sure you are working on the latest code.

3. Create a new branch for your feature based on the current iiSNS master branch

That's very important since you will not be able to submit more than one pull request from your account if you'll use master.

Each separate bug fix or change should go in its own branch. Branch names should be descriptive and start with the number of the issue that your code relates to. If you aren't fixing any particular issue, just skip number. For example:

git checkout upstream/master
git checkout -b 999-name-of-your-branch-goes-here

4. Do your magic, write your code

Make sure it works :)

Unit tests are always welcome. Tested and well covered code greatly simplifies the task of checking your contributions. Failing unit tests as issue description are also accepted.

5. 更新改变记录

编辑名为 “CHANGELOG.md” 的文件来写下你的改变。你应该在文件的顶部,在标题的下面,开启一行来记录你所做的改变。 这一行应是下面这样的:

Bug #999: 修复的 Bug 的描述 (你的姓名)
Enh #999: a description of the enhancement (你的姓名)

#999 is the issue number that the Bug or Enh is referring to. The changelog should be grouped by type (Bug,Enh) and ordered by issue number.

For very small fixes, e.g. typos and documentation changes, there is no need to update the CHANGELOG.

6. Commit your changes

add the files/changes you want to commit to the staging area with

git add path/to/my/file.php

You can use the -p option to select the changes you want to have in your commit.

Commit your changes with a descriptive commit message. Make sure to mention the ticket number with #XXX so GitHub will automatically link your commit with the ticket:

git commit -m "A brief description of this change which fixes #999 goes here"

7. Pull the latest iiSNS code from upstream into your branch

git pull upstream master

This ensures you have the latest code in your branch before you open your pull request. If there are any merge conflicts, you should fix them now and commit the changes again. This ensures that it's easy for the iiSNS team to merge your changes with one click.

8. Having resolved any conflicts, push your code to GitHub

git push -u origin 999-name-of-your-branch-goes-here

The -u parameter ensures that your branch will now automatically push and pull from the GitHub branch. That means if you type git push the next time it will know where to push to. This is useful if you want to later add more commits to the pull request.

9. Open a pull request against upstream.

Go to your repository on GitHub and click "Pull Request", choose your branch on the right and enter some more details in the comment box. To link the pull request to the issue put anywhere in the pull comment #999 where 999 is the issue number.

Note that each pull-request should fix a single change. For multiple, unrelated changes, please open multiple pull requests.

10. Someone will review your code

Someone will review your code, and you might be asked to make some changes, if so go to step #6 (you don't need to open another pull request if your current one is still open). If your code is accepted it will be merged into the main branch and become part of the next iiSNS release. If not, don't be disheartened, different people need different features and iiSNS can't be everything to everyone, your code will still be available on GitHub as a reference for people who need it.

11. Cleaning it up

After your code was either accepted or declined you can delete branches you've worked with from your local repository and origin.

git checkout master
git branch -D 999-name-of-your-branch-goes-here
git push origin --delete 999-name-of-your-branch-goes-here

Note:

To detect regressions early every merge to the iiSNS codebase on GitHub will be picked up by Travis CI for an automated testrun. As core team doesn't wish to overtax this service, [ci skip] will be included to the merge description if the pull request:

  • affect javascript, css or image files only,
  • updates the documentation,
  • modify fixed strings only (e.g. translation updates)

Doing so will save travis from commencing testruns on changes that are not covered by tests in the first place.

Command overview (for advanced contributors)

git clone [email protected]:YOUR-GITHUB-USERNAME/iisns.git
git remote add upstream git://github.com/yiisoft/iisns.git
git fetch upstream
git checkout upstream/master
git checkout -b 999-name-of-your-branch-goes-here

/* do your magic, update changelog if needed */

git add path/to/my/file.php
git commit -m "A brief description of this change which fixes #999 goes here"
git pull upstream master
git push -u origin 999-name-of-your-branch-goes-here