def main(): ap = argparse.ArgumentParser(description="Pull updates from hg", prog="git hg pull") args = ap.parse_args(sys.argv[1:]) # Make sure our config dict contains the stuff we need ghg.include_hg_setup() # Do some sanity checks to make sure we're where we think we are ghg.ensure_is_ghg() # Update the private remote git repo ghg.update_remote() # Now pull those changes into our local repo os.system("git pull hg") return 0
def main(): ap = argparse.ArgumentParser(description='Push to an hg repository', prog='git hg push') ap.add_argument('gitbranch', help='Local git branch to push') ap.add_argument('hgbranch', nargs='?', help='Remote hg branch to push to') args = ap.parse_args(sys.argv[1:]) if not args.hgbranch: args.hgbranch = args.gitbranch # Make sure our config dict contains the stuff we need ghg.include_hg_setup() # Do some sanity checks to make sure we're where we think we are ghg.ensure_is_ghg() # Make sure we'll error if things have changed somewhere else ghg.update_remote() debug = file(pgl.config['HG_DEBUG'], 'a') debug.write('=' * 70) debug.write('\n') start = int(time.time()) debug.write('STARTING GIT->HG EXPORT @ %s\n' % (time.ctime(start).upper(),)) debug.write('GIT BRANCH: %s\n' % (args.gitbranch,)) debug.write('HG BRANCH: %s\n' % (args.hgbranch,)) debug.write('\n') cmd = 'git push hg %s:hg/%s' % (args.gitbranch, args.hgbranch) debug.write('=> %s\n' % cmd) os.system(cmd) debug.write('\n') import_args = ['hg', '--debug', '-v', '--config', 'extensions.hggit=', 'gimport'] debug.write('=> %s\n' % ' '.join(import_args)) importer = subprocess.Popen(import_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=pgl.config['HG_REPO']) for line in importer.stdout: if line.startswith('importing: '): bits = line.strip().split() if len(bits) > 2: sys.stdout.write('\r%s' % (' ' * 70,)) sys.stdout.write('\rExporting revision %s %s' % (bits[1], bits[3])) sys.stdout.flush() debug.write(line) sys.stdout.write('\n') sys.stdout.flush() debug.write('\n') rval = importer.wait() if rval: sys.stderr.write('Some error occurred exporting to hg\n') else: oldcwd = os.getcwd() os.chdir(pgl.config['HG_REPO']) rval = os.system('hg push') os.chdir(oldcwd) end = int(time.time()) debug.write('FINISHED HG->GIT EXPORT @ %s\n' % (time.ctime(end).upper(),)) debug.write('ELAPSED TIME: %s SEC\n' % (end - start,)) debug.write('=' * 70) debug.write('\n') debug.write('\n') debug.close() return rval
def main(): ap = argparse.ArgumentParser(description='Clone an hg repository', prog='git hg clone') ap.add_argument('url', help='URL of HG repository') ap.add_argument('path', nargs='?', help='Destination directory') args = ap.parse_args(sys.argv[1:]) if not args.path: args.path = os.path.join(os.getcwd(), os.path.basename(args.url)) # Figure out the absolute path to our repo if not os.path.isabs(args.path): args.path = os.path.join(os.getcwd(), args.path) args.path = os.path.abspath(args.path) # Create our git repo os.mkdir(args.path) os.chdir(args.path) os.system('git init') # Create our bare hg repo under the git metadir sys.stdout.write('Cloning hg repository\n') sys.stdout.flush() os.chdir('.git') os.mkdir('hg') os.chdir('hg') os.system('hg clone -U "%s" repo' % (args.url,)) # Configure hg-git to put our .git directory alongside our .hg directory os.chdir('repo') os.chdir('.hg') conf = cp.RawConfigParser() conf.read('hgrc') conf.add_section('git') conf.set('git', 'intree', 'True') with file('hgrc', 'w') as f: conf.write(f) # These variables were missing from our config. pgl.config['GIT_TOPLEVEL'] = args.path pgl.config['GIT_DIR'] = os.path.join(args.path, '.git') ghg.include_hg_setup() # Go back to the root of our git repo and make go on the export sys.stdout.write('Converting hg->git (this may take a while)\n') sys.stdout.flush() os.chdir(args.path) ghg.hg2git() # Create hg remote for local repo os.chdir(args.path) start = len(pgl.config['GIT_TOPLEVEL']) if os.path.split(pgl.config['GIT_TOPLEVEL'])[-1]: start += 1 remote_path = pgl.config['HG_GIT_REPO'][start:] os.system('git config remote.hg.url %s' % (remote_path,)) os.system('git config remote.hg.fetch +refs/heads/hg/*:refs/remotes/hg/*') # Set up our master branch to track hg's default os.system('git config branch.master.remote hg') os.system('git config branch.master.merge refs/heads/hg/master') if pgl.config.get('branch.autosetuprebase', None) in ('remote', 'always'): os.system('git config branch.master.rebase true') # Get all the info from our private remote os.system('git fetch hg') # Finally, checkout our master branch os.system('git reset --hard hg/master') return 0