Installation help

 
 
Picture of Rodney Wolford
Got Git installed in my existing Moodle site. Here is How!
 
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.

 
Average of ratings:Useful (4)
Mary Cooch
Re: Got Git installed in my existing Moodle site. Here is How!
Group Documentation writersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup TestersGroup Translators

Thanks for posting your findings; I added your post to the Git for Administrators Moodle docs page.

 
Average of ratings: -
Picture of Rodney Wolford
Re: Got Git installed in my existing Moodle site. Here is How!
 

Mary,

Very glad to hear that it might be of use to others. Unfortunately, I made a small error in the commands as I was generalizing them.

Step 3. commands should say:

-bash-3.2$ cp-rp newmoodle/.git oldmoodle/.git  -- we are copying the new into the old

-bash-3.2$ cd oldmoodle   --not to the newmoodle, which was installed just as a repository

Rest of the commands remain the same.

Sorry about that. Don't imagine there is any easy way to change the document to clear that mistake up?

 

Regards,


Rod

 
Average of ratings:Useful (1)
Mary Cooch
Re: Got Git installed in my existing Moodle site. Here is How!
Group Documentation writersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup TestersGroup Translators

Don't worry - I have linked to this forum discussion so when they read it, they will read your correction too (and my reassurance herebig grin)

 
Average of ratings: -
Picture of Stephen Carter
Re: Got Git installed in my existing Moodle site. Here is How!
 

Hi Rod

Thanks for documenting your steps here. I've just finished successfully initing, cloning, branching, reseting, pulling, adding etc etc and it worked really well.

I found that working through some of the details on gitref.org was a real help in the first instance. I played with that for a while to get a basic idea. Having done that I was able to understand your instructions and got it working first time.

Our site is now on the 2.3.3+ branch. Now to work out how to upgrade to 2.4. Imagine that it will be relatively easier now I am underway.

 

Thanks Again

Stephen Carter

 
Average of ratings: -
Picture of Howard Miller
Re: Got Git installed in my existing Moodle site. Here is How!
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Yike wide eyes 

The big trick here, in case anybody missed it, is copying just the .git directory from a 'Git' install of Moodle to a 'non-Git' install of Moodle. We use this trick all the time to identify changes that other people have made. The other trick is to find the exact commit for the version of code they are running and check that out. Personally I do that bit *before* copying the .git directory over.

After that 'git status' shows you their changes and you can then just create a new branch and commit them.

All reasonably advanced stuff!

 
Average of ratings:Useful (2)
Picture of Ken Task
Re: Got Git installed in my existing Moodle site. Here is How!
Group Particularly helpful Moodlers

Found another reference which looks good:

http://gitref.org/

Lot's to learn with Git so please educate.  Had nerver found the way to set an existing  Moodle code directory which was either created the 'long way' or via CVS update to git, so thanks for sharing back (we need more of that in forums!).

Know the version.php file has the info for current version/build date, etc and with fgrep '$release' version.php that can be displayed.

"find the exact commit for the version of code they are running and check that out"  Example please.

"create a new branch and commit" again example please.

'spirit of sharing' ... and teaching and learning,
 Ken

 
Average of ratings: -
Picture of Rodney Wolford
Re: Got Git installed in my existing Moodle site. Here is How!
 

Hi Ken,

This is Rod, and thanks again for getting me started with your copy command that got the git into the non-git installation. Here's sharing back. You asked for examples of: "find the exact commit for the version of code they are running and check that out" and "create a new branch and commit."  It all begins with the git log command.

1. Take any location that is git configured. Now, just type git log and you will get the display of the commits. 

2. look through the list and pick the most recent, usually at the top, or any other commit you might want, based upon the release version. Copy the first 8 or so characters of the hash following the commit.

3. Now, just type this command git reset -- hard [the 8 or so characters you copied] This will set the head of the git at that location.

4. Now, you check out that branch by using the command git checkout [the 8 or so characters you copied]

After that is git add. to add the branch to your current version then git commit -m commit the changes.

Just try the first 4 steps and you'll see it all displayed for you.

Rod

 
Average of ratings: -
Picture of Howard Miller
Re: Got Git installed in my existing Moodle site. Here is How!
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Ok... here's some more information.

The scenario: You have some Moodle code which has had hacks and changes made to it that you want/need to keep. It isn't in Git and you want to get the changes into git and go from there. If your Moodle is just 'vanilla' then stop here. You don't care, just get a fresh version from Git. Done.

The plan: what we want to do is to checkout of Git the *exact* version of Moodle that your current version started as before you started making changes. Having done that, it's trivial-ish to see what they difference is. I am assuming you know basic git commands and, caveat, this probably isn't the only way or even the easiest and is certainly not for the faint of heart!!

- pull the moodle repository from Git
- in your current version find the version.php file and get the build date out of it (e.g. '2.2.5+ (Build: 20121005)')
- in you Git Moodle, you want to find the exact commit that wrote the version file.
- then use the so-called 'pickaxe' command to locate the commit for your build (e.g. git log -S20120601 version.php). You should get one, but sometimes more if more than  one branch has the same build.
- if you have more, use git show on each commit to get the right one (the right branch). Having establised that simply create a branch and check it out using the commit SHA1 (e.g. git checkout -b mybasecode 3215955fd0e )
- what you have now is the 'clean' code without any of the changes. Make a quick sanity check to double check the basics looks the same.

Now the tricky bit - the hidden .git folder can now be copied over (recursively with contents) to your original code. Having a .git folder is all that makes something a git repository. So, go to your original code and type git status, and there's all the files you changed. You can now commit them or do whatever you like.

As Petr points out there are some gotchas (e.g. CVS can add stuff to the checked out files - evil but there you go) but if you're lucky that'll do it. You'll know it's gone wrong when git status shows that every file has changed wink

 
Average of ratings: -
Picture of Stephen Carter
Re: Got Git installed in my existing Moodle site. Here is How!
 

Thanks for the reference Ken. I've been trying to learn about GIT for a couple of hours now and the site you referenced is the best resource I've seen so far.

Cheers

Stephen

 
Average of ratings: -
Picture of Petr Škoda
Re: Got Git installed in my existing Moodle site. Here is How!
Group DevelopersGroup Documentation writersGroup Moodle HQGroup Particularly helpful Moodlers
Hmm, I have introduced a file called githash.php into CVS when we were transitioning to git, it tells you which git commit should be used for the migration - see for example http://cvs.moodle.org/moodle/githash.php?revision=1.115&view=markup

Please note CVS+tarballs and git files may have different whitespace, so make sure to ignore it when looking for changes.
 
Average of ratings: -
Picture of Howard Miller
Re: Got Git installed in my existing Moodle site. Here is How!
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Yes - we used to have to run a script to strip out all the CVS oddness but I haven't seen a CVS derived Moodle in a long time now.

 
Average of ratings: -
Picture of Faris Raouf
Re: Got Git installed in my existing Moodle site. Here is How!
 

I'm afraid I'm missing a piece of the jigsaw and could do with a pointer please. I'm posting here because I think it might help others in the future as I'm sure someone will have a similar issue.

Having followed your wonderful and clear instructions (including the corrections), I easily got tot he point where my moodle installation was upgraded to (in my case) 2.2.7+ which is what I wanted.

However, having done all that, from within my live and recently updated Moodle directory, when I do a git pull (which is how I would expect to update next time round) as per the GIT for Administrators page, I get:

You are not currently on a branch. Please specify which branch you want to merge with. See git-pull(1) for details.

    git pull <remote> <branch>

So it seems I've disconnected myself from the MOODLE_22_STABLE branch that git was previously "connected" to.

git status gives me

# Not currently on any branch.
nothing to commit (working directory clean)

Sooo......

# git branch -a
* (no branch)
  MOODLE_22_STABLE
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MOODLE_13_STABLE
  remotes/origin/MOODLE_14_STABLE
  remotes/origin/MOODLE_15_STABLE
  remotes/origin/MOODLE_16_STABLE
  remotes/origin/MOODLE_17_STABLE
  remotes/origin/MOODLE_18_STABLE
  remotes/origin/MOODLE_19_STABLE
  remotes/origin/MOODLE_20_STABLE
  remotes/origin/MOODLE_21_STABLE
  remotes/origin/MOODLE_22_STABLE
  remotes/origin/MOODLE_23_STABLE
  remotes/origin/MOODLE_24_STABLE
  remotes/origin/master

At this point I'm not completely sure what to do. I can see what looks like a local MOODLE_22_STABLE and a remote MOODLE_22_STABLE in that list, but I'm really confused as to what I need to do next in order to be able to just "git pull" to update. I can guess, but I don't want to guess incorrectly!

EDIT:

My guess:

git checkout MOODLE_22_STABLE

And certainly it sort of looks right:

# branch -a
* MOODLE_22_STABLE
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MOODLE_13_STABLE
  remotes/origin/MOODLE_14_STABLE
  remotes/origin/MOODLE_15_STABLE
  remotes/origin/MOODLE_16_STABLE
  remotes/origin/MOODLE_17_STABLE
  remotes/origin/MOODLE_18_STABLE
  remotes/origin/MOODLE_19_STABLE
  remotes/origin/MOODLE_20_STABLE
  remotes/origin/MOODLE_21_STABLE
  remotes/origin/MOODLE_22_STABLE
  remotes/origin/MOODLE_23_STABLE
  remotes/origin/MOODLE_24_STABLE
  remotes/origin/master

 

 
Average of ratings: -
Picture of Ken Task
Re: Got Git installed in my existing Moodle site. Here is How!
Group Particularly helpful Moodlers

@Faris Raouf

Looks like you've made the correction ok.

This line:

* MOODLE_22_STABLE

above list of all branches in the local repo indicates that's the branch that will be accessed on the 'git pull' command.

Know the following is a little longer than directions given on the docs page, but ... am old and slow ... and very linear!!! :|

git clone git://git.moodle.org/moodle.git moodle24
cd moodle24
git branch -a
git branch --track MOODLE_24_STABLE origin/MOODLE_24_STABLE
git checkout MOODLE_24_STABLE

You might have skipped the git branch --track line above.

I've gotten into a habit NOT to trust myself so after checkout above, I check myself:

fgrep '$release' version.php

while in the directory just cloned will show release information:

$release  = '2.4.1+ (Build: 20130118)';  // Human-friendly version name

Should be the one you tracked and checked out.

'spirit of sharing', Ken

 
Average of ratings: -
Picture of Faris Raouf
Re: Got Git installed in my existing Moodle site. Here is How!
 

Thanks Ken.

I'm assuming that the "local" MOODLE_XX_STABLE that I'm now connected to was actually originally created through:

git branch --track MOODLE_XX_STABLE origin/MOODLE_XX_STABLE

I definitely did that bit smile (according to my history). But I dissociated myself from it after all the other bits that I had to do with the reset --hard and so on.

There has to be a more streamlined way to switch from cvs to git.

I'm going to make some copies and do some experiments. I can't let this go smile

 
Average of ratings: -
Picture of Ken Task
Re: Got Git installed in my existing Moodle site. Here is How!
Group Particularly helpful Moodlers

@Faris Raouf et. al.

Have a school site with 31 instances that had been maintained via CVS.  The last security announcement (which included 1.9.x) and the fact that CVS no longer being provded forced me to 'convert' all the sites from CVS to git.

This is kinda a spin off using older directions in upgrading a site but with a git twist. [site] below is the original folder name ... could be 'moodle' ... and is a 'variable'.  Don't try to run the lines below without subing for [site]

1st created a git directory to replace the CVS maintained site.

git clone git://git.moodle.org/moodle.git  [site]git

the '[site]git'  at the same level as the original site

cd [site]git;
git branch -a;
git branch --track MOODLE_19_STABLE origin/MOODLE_19_STABLE;
git checkout MOODLE_19_STABLE;
cp ../[site]/config.php .

Then copied the add-on themes, mod, blocks, filters, admin/reports, etc. from the original [site] folder to the [site]git folder.

Example from original [site]/blocks directory

cp -rp email_list/ exabis_eportfolio/ quickmail/ youtube_video/ ../../[site]git/blocks/

The cp -rp does recursive and preserves ownerships
Did cp rather than mv in case things blew up! ;)

Same for themes.  Same for mods, etc.

chown apache:apache [site]git -R

Moved the original [site] to [site].back
Moved the [site]git to [site]

Hit with browser and login as admin user.  That did do the minor upgrade.  Am now with a git maintained 1.9.x site that's updatable via git (git pull) and if the decision is to attempt migration in place, am ready to 'move upwards'.

Wrote a simple script for all the above and after testing the script with a sandbox site, it took about 2 hours (31 sites) and most of that time typing my script with the 2 required parameters (1 minute at most) and longer in the Web interface stepping through the minor upgrade.

Attached is 'dogitscript.txt' ... for Linux (but could be adjusted for powershell or some Winders thang).  It would need to be edited for your situation.

Granted you may not have multiple sites and not in need of such a thing, but by inspecting, one can engineer to suit needs.

Did the same thing for Mdl2's only reading a text file listing of Moodle 2 sites into a similar script that also ran the admin/cli/upgrade.php script.  No login to Moodle required.  Sweet! ;)

Found this 'git twist' a little easier to wrap my feeble and failing gray cells around.

'spirit of sharing', Ken

 
Average of ratings: -
Picture of Simon Bryan
Re: Got Git installed in my existing Moodle site. Here is How!
 

Just jumping in cause this all very confusing!! CVS was so easy  smile

So if I hve my manually created moodle folder at /var/www/html/moodle

I would run the above set of commands from /var/www/html?

Cheers

Simon

 
Average of ratings: -
Picture of Ken Task
Re: Got Git installed in my existing Moodle site. Here is How!
Group Particularly helpful Moodlers

Yes, I agree ... it is confusing ... at first.  Like many things moodle it is recommended to tinker on a non-production site first.

Glad to play a part in Rodney's 'adventure' and he definitly dug into it for an existing moodle code directory.  He is indeed correct.  Just think that there is/might be an easier transition method ... that's all ... and that's what I'm sharing! ;)

Do you have existing moodle code in the moodle directory and is it your currently active site?

if so, git won't (without more commands than shown in the Moodle docs and the additional steps shown in the first posting here in this thread) update/create/change any files/folders in an existing moodle code directory.  One good thing about it ... one 'gets into git' .... deep!  Nothing wrong with that.  I, myself, might be re-visiting this thread to re-read what Rodney did ... should I have the need later (hope not!).

In the older documentation for upgrading a site, they advised renaming the existing moodle folder to 'moodle.back', unzipping a download, using FTP to upload to a 'moodle' directory on the site and then copy the addons/themes and config.php file to the newly created moodle directory.   That's probably why you went to CVS, huh?

My method is similar to that ... cept it's on the server using git and there is no download/upload issues.

In your case, and if using my 'twist', one would issue the commands at /var/www/html/ and the directory you are creating with the first git command I'd recommend be 'moodlegit'.

 

git clone git://git.moodle.org/moodle.git moodlegit

cd moodlegit

git branch -a

git branch --track MOODLE_XX_STABLE origin/MOODLE_XX_STABLE

git checkout MOODLE_XX_STABLE

After 'moodlegit' directory as been configured to track the SAME version you already have in the 'moodle' directory, then cp -rp the mods/blocks/themes that are NOT core into the mod/block/theme directory of the 'moodlegit' folder.  Copy the config.php file also from 'moodle' to 'moodlegit'.

Change ownerships/permissons on 'moodlegit' as per system dictates ... in my case ... CentOS so from /var/www/html/

chown apache:apache moodlegit -R

IF one is ready and double checked themes/blocks/mods, then all one needs to do is 'swap' the folders ...

mv moodle moodle.back

(renames the 'moodle' folder to 'moodle.back')

mv moodlegit moodle

(renames the 'moodlegit' folder to that which is accessed by URL 'moodle').

Then hit site with browser and login.

That help?

Once that is done and it's working, then it's like CVS in that one executes 'git pull' *inside* the 'moodle' directory.

BTW, am not saying by any means/form/or fashion that my 'twist method' is the best, but I think it dives into git less than other methods right now and gets the job done.  One should set aside some time to tinker with git ... just not on active production server, but a 'tinker' instance.

'spirit of sharing', Ken

 
Average of ratings:Useful (2)
Picture of Simon Bryan
Re: Got Git installed in my existing Moodle site. Here is How!
 

ABsolutley perfect instructions - just what I needed. Did not wnt to become a git expert just update Moodle!! 

All working and reports up to date.

 

Cheers and thanks again Ken

 
Average of ratings: -
Picture of Ken Task
Re: Got Git installed in my existing Moodle site. Here is How!
Group Particularly helpful Moodlers

Great!  Glad to hear it.  Feel free to rate the post that helped as 'Useful'! ;)

'spirit of sharing', Ken

 
Average of ratings: -
Picture of Simon Bryan
Re: Got Git installed in my existing Moodle site. Here is How!
 
Done! Didn't realise there were ratings
 
Average of ratings: -