About a week ago, I posted my problem: A Moodle 2.3.1 installed on a linux server. Trying to follow the steps outlined in git for administrators as well as I could and not getting anywhere. (see my earlier post "Can’t get git to update my Moodle Install.")
Ken Task, responded to my request for assistance, and led me through the basic steps needed to establish a git repository in my existing moodle installation (thank you very much Ken).
At that point, I was still getting errors when trying to do the git pull from within my existing moodle installation. So, I set about trying to dig up a set of git commands to do it. I was aided by a fantastic git resource I found, http://www-cs-students.stanford.edu/~blynn/gitmagic/index.html .
Soon, my install was done. Because I have seen many other users having the same problem, I wanted to share what I have learned. I want to point out that I am neither a command line expert nor a git expert nor a moodle expert, so if you use any of this, it would be at your own hazard. However, it may be of some help and maybe somebody else will add some insights that will benefit me and others. So, Here goes:
Terms
oldmoodle - my existing moodle site that I want to upgrade
newmoodle - the place where I initially place git as if I were doing a new install using git.
1. From a level where you can see your oldmoodle directory use the commands in the Moodle Git for Administrators document:
-bash-3.2$ git clone git://git.moodle.org/newmoodle.git
-bash-3.2$ cd newmoodle
-bash-3.2$ git branch -a
-bash-3.2$ git branch --track MOODLE_23_STABLE origin/MOODLE_23_STABLE
-bash-3.2$ git checkout MOODLE_23_STABLE
This verifies that the git moodle exists and that it contains all branches, etc.
2. So far so good. Next step is to move the git MOODLE_23_STABLE branch from the newmoodle folder into your oldmoodle folder. But first, BACKUP your site!
-bash-3.2$ cd /var/www/html/ (or httpdocs ... where ever oldmoodle is located.
-bash-3.2$ tar -cvf oldmoodlesite.tar ./oldmoodle
That backs up the oldmoodle directory to a tar ball which keeps permissions and everything in it. We could use this to restore the code directory.
Because the upgrade may also affect the DB, do a DB dump of the database for oldmoodle mdl.
-bash-3.2$ mysqldump -u root -p [database-4- oldmoodle] > oldmoodledatadump[today’s date].sql
3. Now, from a level where one can see both newmoodle and oldmoodle directories, use the following commands:
-bash-3.2$ cp -rp moodle/.git newmoodle/.git
The '-r' is recursive. The 'p' preserves ownership/permissions. This copies the git from the newmoodle directory into the oldmoodle directory. Now, try it out
-bash-3.2$ cd newmoodle
-bash-3.2$ git branch -a
-bash-3.2$ git pull
If it works, you are done, just as Moodle's Git for Administrators says. Use next command to check release version is correct.
-bash-3.2$ fgrep '$release' version.php
If, as was my case, you get either an “up to date” message or an error saying “can’t copy over files, ABORT” and you use the next command and you will see you are still at your old version in your oldmoodle directory. The git didn’t git. And nothing I found in the forums provided an answer.
-bash-3.2$ fgrep '$release' version.php
4. So, here is where I got help from the "GitMagic" publication. Next step, get the git log to determine the top most commit.
-bash-3.2$ git log -- below is the result I got, I have highlighted the commit hash I used. Yours may be different.
commit 562dbe408e7f32afc8c7cac8b05b2d0a261c4b28 -- this is it!
Author: Eloy Lafuente (stronk7) <stronk7@moodle.org>
Date: Fri Oct 5 13:38:50 2012 +0200
weekly release 2.3.2+
commit 035997329ae28551befd6b520ad1741d7444f0d7
Merge: 4abc5a1 0a1c7a1
Author: Eloy Lafuente (stronk7) <stronk7@moodle.org>
Date: Fri Oct 5 13:33:02 2012 +0200
Merge branch 'install_23_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_2
commit 4abc5a1a2c2755d9f7ea60e7ae53d2f2007e33c5
Author: Eloy Lafuente (stronk7) <stronk7@moodle.org>
Date: Fri Oct 5 13:10:06 2012 +0200
Revert "MDL-34257 quiz 'secure' mode: PAGE initialisation order issues."
This reverts commit d205afe662ba306833a525d87714d1994467dba7.
commit db8e84ae1a81508dc55e705cc82489e41e495141
Author: Dan Poltawski <dan@moodle.com>
Date: Fri Oct 5 16:20:52 2012 +0800
5. Now, you will use the hash from the git log to set git where you want it and to check it out.
-bash-3.2$ git reset --hard 562dbe408e7f32 -- sets the head to the release you want
HEAD is now at 562dbe4 weekly release 2.3.2+
-bash-3.2$ git checkout 562dbe408e7f32 -- checks out the release you want
Note: checking out '562dbe408e7f32'.
HEAD is now at 562dbe4... weekly release 2.3.2+
6. At this point, I reinitialized the git repository (may not be necessary, I don’t know).
-bash-3.2$ git init -- reinitializes the existing git repository
Reinitialized existing Git repository in /var/www/vhosts/your_site/httpdocs/oldmoodle/.git/
7. At this point, you need to add the changes to the reinitialized git repository.
-bash-3.2$ git add .
8. Then commit what you have added.
-bash-3.2$ git commit -m MOODLE_23_STABLE – commits the changes
[detached HEAD e5dfe2b] MOODLE_23_STABLE
100 files changed, 11061 insertions(+)
create mode 100644 lib/editor/tinymce/tiny_mce/3.5.1.1/license.txt~Stashed changes
create mode 100644 lib/editor/tinymce/tiny_mce/3.5.1.1/plugins/advhr/css/advhr.css~Stashed changes ….
….this list will go on for quite some time as it “creates and changes the stash……. When done:
-bash-3.2$ git stash -- a way to test that all local changes are done if No changes to save, then Success!
No local changes to save
-bash-3.2$ git stash pop – this reveals any untracked working tree files that are not updated that might result in problems. If desired, can go into the oldmoodle site and move these out then run the command again. Fortunately, none of these were critical in my case, so, what, Me Worry!?
9. Finally, just used browser to go to siteoldmoodleto log in as administrator and followed upgrade instructions. Did have to move custom theme for site into themes folder manually after install was done.
Anyway, this is what I did with the help of Ken Task and I thought it was important to share it. I’m sure there are better ways and maybe this won’t work for anyone else. But it seems like a topic that should be discussed.