**Examples**
-In a Moodle 2.2 instance, this will create a branch named MDL-12345-22 which will track origin/MOODLE_22_STABLE.
+In a Moodle 2.2 instance, this will create a branch named MDL-12345-22 which will track upstream/MOODLE_22_STABLE.
moodle fix MDL-12345
moodle fix 12345
### - rebase
-Fetch the latest branches from origin and rebase your local branches.
+Fetch the latest branches from the upstream remote and rebase your local branches.
**Examples**
### - update
-Fetch the latest stables branches from the origin and pull the changes into the local stable branch.
+Fetch the latest stables branches from the upstream remote and pull the changes into the local stable branch.
**Examples**
"pgsql": "PostgreSQL"
},
-
// The host name to set during an install
"host": "localhost",
// Moodle admin login
"login": "admin",
// Moodle admin password
"passwd": "test",
- // What to call your remote, do not call that origin!
- "myRemote": "github",
+ // What to call your remote, the one pointing to remotes.mine
+ "myRemote": "origin",
+ // What to call the upstream remote, the one pointing to the official repositoriy (stable or integration)
+ "upstreamRemote": "upstream",
// The name of the data directory
"dataDir": "moodledata",
// Path to PHP
"php": "/usr/bin/php",
- // Experimental setting to use a local cache as your origin remotes.
+ // Experimental setting to use a local cache as your upstream remotes.
// Can be useful to prevent fetch from a slow remote.
"useCacheAsRemote": false,
"""
import os
+import re
import shlex
import subprocess
else:
return result[1].replace('refs/heads/', '').strip()
+ def delRemote(self, remote):
+ cmd = 'remote rm %s' % remote
+ result = self.execute(cmd)
+ return result[0] == 0
+
def execute(self, cmd, path = None):
if path == None:
path = self.getPath()
else:
return None
+ def getRemote(self, remote):
+ remotes = self.getRemotes()
+ return remotes.get(remote, None)
+
+ def getRemotes(self):
+ """Return the remotes"""
+ cmd = 'remote -v'
+ result = self.execute(cmd)
+ remotes = None
+ if result[0] == 0:
+ remotes = {}
+ for line in result[1].split('\n'):
+ if not line: continue
+ (remote, repo) = re.split('\s+', line, 1)
+ repo = re.sub(' \(push\)|\(fetch\)$', '', repo)
+ remotes[remote] = repo
+ return remotes
+
def hasBranch(self, branch, remote = ''):
if remote != '':
cmd = 'show-ref --verify --quiet "refs/remotes/%s/%s"' % (remote, branch)
result = self.execute(cmd)
return result[0] == 0
+ def setRemote(self, remote, url):
+ if not self.getRemote(remote):
+ cmd = 'remote add %s %s' % (remote, url)
+ else:
+ cmd = 'remote set-url %s %s' % (remote, url)
+ result = self.execute(cmd)
+ return result[0] == 0
+
def stash(self, command = 'save', untracked = False):
cmd = 'stash %s' % command
if untracked:
def isIntegration(self):
"""Returns whether an instance is an integration one or not"""
- remote = self.git().getConfig('remote.origin.url')
+ remote = self.git().getConfig('remote.%s.url' % C.get('upstreamRemote'))
if remote != None and remote.endswith('integration.git'):
return True
return False
os.remove(dest)
return result[0]
- def update(self, remote = 'origin'):
+ def update(self, remote = None):
"""Update the instance from the remote"""
+ if remote == None:
+ remote = C.get('upstreamRemote')
+
# Fetch
if not self.git().fetch(remote):
raise Exception('Could not fetch remote %s' % remote)
if integration:
repository = os.path.join(self.cache, 'integration.git')
+ upstreamRepository = C.get('remotes.integration')
else:
repository = os.path.join(self.cache, 'moodle.git')
+ upstreamRepository = C.get('remotes.stable')
# Clone the instances
debug('Cloning repository...')
if useCacheAsRemote:
result = process('%s clone %s %s' % (C.get('git'), repository, wwwDir))
+ upstreamRepository = repository
else:
copy_tree(repository, wwwDir)
if not os.path.isfile(linkDataDir) and not os.path.isdir(linkDataDir) and not os.path.islink(linkDataDir):
os.symlink(dataDir, linkDataDir)
- # Creating, fetch, pulling branches
debug('Checking out branch...')
repo = git.Git(wwwDir, C.get('git'))
- result = repo.fetch('origin')
+
+ # Setting up the correct remote names
+ repo.setRemote(C.get('myRemote'), C.get('remotes.mine'))
+ repo.setRemote(C.get('upstreamRemote'), upstreamRepository)
+
+ # Creating, fetch, pulling branches
+ result = repo.fetch(C.get('upstreamRemote'))
if version == 'master':
repo.checkout('master')
else:
- track = 'origin/MOODLE_%s_STABLE' % version
+ track = '%s/MOODLE_%s_STABLE' % (C.get('upstreamRemote'), version)
branch = 'MOODLE_%s_STABLE' % version
if not repo.createBranch(branch, track):
debug('Could not create branch %s tracking %s' % (branch, track))
else:
repo.checkout(branch)
- repo.pull()
- repo.addRemote(C.get('myRemote'), C.get('remotes.mine'))
+ repo.pull(remote = C.get('upstreamRemote'))
M = self.get(name)
return M
raise Exception('Could not create branch %s tracking %s in repository %s' % (branch, track, cache))
if not repo.checkout(branch):
- raise exception('error while checking out branch %s in repository %s' % (branch, cache))
+ raise Exception('Error while checking out branch %s in repository %s' % (branch, cache))
if not repo.reset(to = track, hard = True):
raise Exception('Could not hard reset to %s in repository %s' % (branch, cache))
# Creates a new branch if necessary
newbranch = M2.generateBranchName(issue, suffix=suffix)
- track = 'origin/%s' % M2.get('stablebranch')
+ track = '%s/%s' % (C.get('upstreamRemote'), M2.get('stablebranch'))
if not M2.git().hasBranch(newbranch):
debug('Creating branch %s' % newbranch)
if not M2.git().createBranch(newbranch, track=track):
debug('Hard reset to %s' % (track))
M2.git().reset(to=track, hard=True)
- # Picking the diff origin/MOODLE_23_STABLE..github/MDL-12345-master
- cherry = 'origin/%s..%s/%s' % (originaltrack, remote, branch)
+ # Picking the diff upstream/MOODLE_23_STABLE..github/MDL-12345-master
+ cherry = '%s/%s..%s/%s' % (C.get('upstreamRemote'), originaltrack, remote, branch)
debug('Cherry-picking %s' % (cherry))
result = M2.git().pick(cherry)
if result[0] != 0:
branch = M.generateBranchName(args.issue, suffix=args.suffix)
# Track
-track = 'origin/%s' % M.get('stablebranch')
+track = '%s/%s' % (C.get('upstreamRemote'), M.get('stablebranch'))
# Git repo
repo = M.git()
# Loops over instances to rebase
for M in Mlist:
debug('Working on %s' % (M.get('identifier')))
- M.git().fetch('origin')
+ M.git().fetch(C.get('upstreamRemote'))
# Test if currently in a detached branch
if M.git().currentBranch() == 'HEAD':
# Rebase
debug('> Rebasing %s...' % (branch))
- base = 'origin/%s' % M.get('stablebranch')
+ base = '%s/%s' % (C.get('upstreamRemote'), M.get('stablebranch'))
result = M.git().rebase(branch=branch, base=base)
if result[0] != 0:
debug('Error while rebasing branch %s on top of %s' % (branch, base))