Google Code In
Basic Commands : 1. To work on present working directory, type: pwd
2. To see list of things in the directory : ls
3. To change the directory from your home directory to other directory (for eg.drupal directory) : cd path_location_to_drupal_directory
Basic Configuration :
Git Basics
Git is a tool which helps you to manage your changes to the code and also helps to track changes made in a file, thus, it is used to made a patch which involves the difference between changes in the two files.
Installing Git :
1. For windows download the latest version from the following link. and then run the installer. To confirm, whether git has been installed or not type git by opening the command prompt. If there are no errors, you are good to go!
2. For Mac, use Macports and type the following command :
$ sudo port install git-core +bash_completion +doc +gitweb +svn
3. For Linux, type the following command on Terminal :
$ sudo apt-get install git-coreBasic Commands : 1. To work on present working directory, type: pwd
2. To see list of things in the directory : ls
3. To change the directory from your home directory to other directory (for eg.drupal directory) : cd path_location_to_drupal_directory
Basic Configuration :
1. Choose the name which will be suitable for publicly associating yourself with the commits.
$ git config --global user.name "Your Name"
2. Provide an email address through which anybody can contact you.
$ git config --global user.email yourname@example.com
3. Setting git for using automatic line endings.
$ git config --global core.autocrlf true
Installing Drupal:
1. Type the following command in the terminal for installing Drupal:
git clone http://git.drupal.org/project/drupal.git
2. Check on which branch you are by typing the following command :
git checkout 8.0.x
Download a Project Using Git :
1. Move to your modules folder in the drupal directory and download a project (here I will download admin toolbar project).
git clone --branch 8.x-1.x https://git.drupal.org/project/admin_toolbar.git
Creating a Patch :
We are going to create a patch here to fix the bug which can be found here.
We are going to create a branch for development first , which can be done in the following ways:
1. So, firstly go to the sandbox environment.
cd path/to/drupal-8/sandbox
2. Check whether you are on branch 8.x or not.
git branch
3. Create a branch on where you will work on the patch. The issue is here And the issue no is 1388780.
git branch [issue-number]-rewrite-description-for-url-alias
4. Now, checkout the branch you just created.
git checkout [issue-number]-rewrite-description-for-url-alias
5. Then, confirm that you are on the branch which has been just created.
git branch
Making Edits :
1. Open path.module file by moving to directory : sandbox_project/core/modules/path/path.module
2. First, give issue a look by going to your sandbox directory and then to :
Add content ->
Article or Basic Page -> URL Path Settings.
3. Now, go to line 139 and then replace this :
Optionally specify an alternative URL by which this content can be
accessed. For example, type "about" when writing an about page. Use a
relative path and don't add a trailing slash or the URL alias won't
work.
with this
The alternative URL for this content. Use a relative path without a
trailing slash. For example, type "about" for the about page.
4. Now, go back to your sandbox site and see that the confusing text has been changed to understandable text.
5. To see which files have changes pending , type the following command :
git status
6. To see what changes have been made type:
git diff
7. Revert the changes if you have made any mistake by typing:
git reset --hard
8. Commit the changes by typing :
git commit -am "Issue #[issue-number]. Updated description for URL alias on node form."
Create and Submit a patch :
1. So, to create the patch , get the comment no by seeing on the issue that to which comment your issue will be added.
2. Now, to create the patch type the following command :
git diff 8.x > [description]-[issue-number]-[comment-number].patch
3. Also, check on your branch whether the patch is working or not before submitting the patch.
git checkout 8.x
4. Then apply the patch by typing :
git apply -v [description]-[issue-number]-[comment-number].patch
5. One more thing to do is to revert the changes that you have made on your branch -
git reset --hard
6. Then , finally submit the patch and ensure that the patch file ends with .patch . Also, submit the screenshot for the same.
7. Also, don't forget to change the status to "Needs Review".
Hopefully the patch would have been submitted on the issue queue!
Testing Patches :
Git configuration commands:
Type the following Git Configuration
commands in the terminal to make the command more legible and do
functions like changing the color of diff files :
git config --global color.status auto git config --global color.branch auto git config --global color.interactive auto git config --global color.diff auto
1. Now go to your sandbox directory which you have downloaded by typing cd location_to_sandbox.
2. Check on which branch you are by typing the following command :
$ git branch3. If you are not on the branch , type command : $ git checkout 8.x4. Now download the patch in comment2 in your drupal sandbox directory.
5. Then, go to your sandbox site and give the issue a look. (The help text is confusion as seen in the screenshot below).
6. Now move to your sandbox directory in the terminal and then apply the patch by typing the following command :
git apply 1326088-rewrite-desription-for-url-alias.patch
7. Now, when you will go back to your
site and refresh the page, you will see that the helping text has been
changed and has become quite understandable.
8. Congratulations, the patch has been applied.
Rerolling Patches :
Patches are rerolled to keep them up to date with new versions of drupal.
Steps to reroll the patch -
1. We will be rerolling this patch here. So, to download the corresponding patch type the following command :
git apply --check 1497310-statistics_config_settings-5.patch
2. If the patch is applied cleanly , remove the tag "Needs Re-roll" , but if there are errors , then the patch needs to be rerolled.
3.Then , go to the issue and note the date of the issue and type the following command to apply the patch-
git log -1 --before="March 30, 2012".
4. Now, copy the first few charachters of commit :
git checkout -b cmi-statistics 992692441
5. Try to apply the patch again :
git apply --index 1497310-statistics_config_settings-5.patch
6. Then,do git status to see the changes and then commit the changes :
git commit -m "Applying patch from issue 1497310 comment 5804956"
7. Now, pull all the changes that have happened since time you commited the branch :
git rebase 8.0.x
8. Open core/modules/statistics/statistics.module file and see for the line :
...
/**
* Implements hook_cron().
*/
function statistics_cron() {
<<<<<<< HEAD
$statistics_timestamp = \Drupal::state()->get('statistics.day_timestamp') ?: 0;
=======
$config = config('statistics.settings');
$statistics_timestamp = $config->get('statistics_day_timestamp');
>>>>>>> Applying patch from issue 1497310 comment 5804956
/**
* Implements hook_cron().
*/
function statistics_cron() {
<<<<<<< HEAD
$statistics_timestamp = \Drupal::state()->get('statistics.day_timestamp') ?: 0;
=======
$config = config('statistics.settings');
$statistics_timestamp = $config->get('statistics_day_timestamp');
>>>>>>> Applying patch from issue 1497310 comment 5804956
9. Everything above is good but below it we need to change , so paste this :
function statistics_cron() {
$config = config('statistics.settings');
$statistics_timestamp = $config->get('statistics_day_timestamp');
$config = config('statistics.settings');
$statistics_timestamp = $config->get('statistics_day_timestamp');
10. Now, you can stage your changes with :
git add
11. Finally, create your patch by typing the following command :
git diff 8.0.x cmi-statistics > [description]-[issue-number]-[comment-number].patch
It was a very nice experience working with git . I didn't know that git is too useful.It helped me learned a lot of new things like how to commit changes ,track them and record them into some file. So, I learned a lot of new things and I will keep on contributing to Drupal in future too! 











Comments
Post a Comment