pull_requests.rst 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. .. _pull-requests:
  2. Pull Requests
  3. =============
  4. Pagure uses the concept of pull requests to contribute changes from your fork
  5. of a project back to the upstream project. To contribute a change to a project
  6. you first open a pull request with original project. The project maintainer
  7. then merges the pull request if they are satisfied with the changes you have
  8. proposed.
  9. .. _open-pull-request:
  10. Open a Pull Request
  11. -------------------
  12. Before you can open a pull request, you need to complete the :ref:`first-steps`
  13. and :ref:`create-fork` of the project you would like to contribute to. Once
  14. you have a fork and you have pushed a `git branch <https://git-scm.com/docs/git-branch>`_
  15. containing one or more `commits <https://git-scm.com/docs/git-commit>`_, you are
  16. ready to contribute to the project.
  17. Pagure to Pagure pull request
  18. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  19. You can create a pull request from a pagure project, using one of the following options
  20. From the project overview
  21. *************************
  22. #. Go the the ``overview`` tab of your fork.
  23. #. Locate your feature branch (Right hand side), and press the button ``New PR`` button.
  24. #. Fill the Create a pull request form (Title and Description) and create your pull request.
  25. Notes: The ``New PR`` button appears only if there are commits not available in the main branch.
  26. .. image:: _static/pagure_pr_overview.png
  27. :target: ../_images/pagure_pr_overview.png
  28. From the commits history
  29. ************************
  30. #. Go to the ``commit`` tab of your fork and select your feature branch.
  31. #. Press the ``create pull request`` button (above the latest commits).
  32. #. Fill the Create a pull request form (Title and Description) and create your pull request.
  33. .. image:: _static/pagure_pr_commits.png
  34. :target: ../_images/pagure_pr_commits.png
  35. From the pull requests list
  36. ***************************
  37. #. Go to the main project's (not your fork) pull requests list and press the ``File Pull Request`` button.
  38. #. Select the feature branch containing your changes from the dropdown menu.
  39. #. Fill the Create a pull request form (Title and Description) and create your pull request.
  40. .. image:: _static/pagure_pr_pull_requests.png
  41. :target: ../_images/pagure_pr_pull_requests.png
  42. Remote Git to Pagure pull request
  43. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  44. You can create a pull request from another git hosting platform (e.g. GitHub, GitLab).
  45. This is a remote pull request.
  46. From the pull requests list
  47. ***************************
  48. #. Go to the main project's (not your fork) pull requests list and press the ``File Pull Request`` button.
  49. #. Select the ``Remote pull-request`` option from the dropdown menu.
  50. #. Fill the New remote pull-request form (Title, Git repo address and Git branch) and create your remote pull request.
  51. Congratulations! It is now up to the project maintainer to accept your changes
  52. by merging them.
  53. .. _update-pull-request:
  54. Updating Your Pull Request
  55. --------------------------
  56. It is likely that project maintainers will request changes to your proposed code
  57. by commenting on your pull request. Don't be discouraged! This is an opportunity
  58. to improve your contribution and for both reviewer and reviewee to become better
  59. programmers.
  60. Adding to your pull request is as simple as pushing new commits to the branch you
  61. used to create the pull request. These will automatically be displayed in the
  62. commit list for the pull request.
  63. Rebasing
  64. ^^^^^^^^
  65. You may encounter a situation where you want to include changes from the master
  66. branch that were made after you created your pull request. You can do this by
  67. `rebasing <https://git-scm.com/docs/git-rebase>`_ your pull request branch and
  68. pushing it to your remote fork.
  69. .. _working-with-prs:
  70. Working with Pull Requests
  71. --------------------------
  72. It's quite common to work with a pull request locally, either to build on top of
  73. it or to test it. You can do this easily using ``git fetch`` to download the
  74. pull request followed by ``git checkout`` to work with it as you would any
  75. local branch. The syntax for ``git fetch`` is: ::
  76. git fetch $REMOTE pull/$PR_NUMBER/head:$BRANCHNAME
  77. For example, if you have PR#1 which "adds support for foo" you might run: ::
  78. git fetch origin pull/1/head:add-foo-support
  79. Then you can work with the ``add-foo-support`` normally: ::
  80. git checkout add-foo-support
  81. .. note:: You may use ``/`` characters in your branch name if you want to group
  82. your pull requests by the submitter name, bug number, etc. For
  83. example, you could name your local branch ``user/add-foo-support``.
  84. If you want to allow working with all of your pull requests locally, you can do
  85. so by editing your git configuration as follows.
  86. Locate your remote in the ``.git/config`` file, for example::
  87. [remote "origin"]
  88. url = ssh://git@pagure.io/pagure.git
  89. fetch = +refs/heads/*:refs/remotes/origin/*
  90. Now add this line::
  91. fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
  92. to that section as **the first fetch line**, like this::
  93. [remote "origin"]
  94. url = ssh://git@pagure.io/pagure.git
  95. fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
  96. fetch = +refs/heads/*:refs/remotes/origin/*
  97. Obviously, the remote URL should be matching the URL of your project (pagure project in
  98. this example).
  99. Now you can fetch the all the pull requests: ::
  100. $ git fetch origin
  101. From ssh://pagure.io/pagure
  102. * [new ref] refs/pull/2541/head -> origin/pr/2541
  103. * [new ref] refs/pull/2540/head -> origin/pr/2540
  104. * [new ref] refs/pull/2538/head -> origin/pr/2538
  105. To checkout a particular pull request: ::
  106. $ git checkout pr/25413
  107. Branch pr/2541 set up to track remote branch pr/2541 from origin.
  108. Switched to a new branch 'pr/2541'
  109. You will now be able to use this branch to work from or on this pull requests.
  110. If you are only interested in one particular pull request and do not want to fetch all the project PRs,
  111. you can add to your ``~/.bashrc`` the following function: ::
  112. function pullpr {
  113. remote="${2:-origin}"
  114. git fetch $remote pull/$1/head:pr_$1
  115. git checkout pr_$1
  116. }
  117. Then after sourcing your ``~/.bashrc`` or restarting your shell, you can use the
  118. pullpr function to checkout a pull request from within the clone of the git repository.
  119. For example checkout pull request number 58 from current git clone (here the
  120. infra-docs project) ::
  121. $ source ~/.bashrc
  122. $ pullpr 58
  123. remote: Counting objects: 393, done.
  124. remote: Compressing objects: 100% (238/238), done.
  125. remote: Total 365 (delta 231), reused 255 (delta 127)
  126. Receiving objects: 100% (365/365), 71.36 KiB | 63.00 KiB/s, done.
  127. Resolving deltas: 100% (231/231), completed with 20 local objects.
  128. From ssh://pagure.io/infra-docs
  129. * [new ref] refs/pull/58/head -> pr_58
  130. Switched to branch 'pr_58'