• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python git.commit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sh.git.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了commit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    """
    Requires youtube uploader script from
    https://github.com/tokland/youtube-upload
    """

    from subprocess import Popen, PIPE
    import glob
    from sh import git

    yt_ids = []
    for fname in glob.glob("*.webm"):
        title = fname.replace(".webm", "").replace("_", " ")
        command = 'youtube-upload --title="' + title + '" ' + fname
        p = Popen(command, stdout=PIPE, shell=True)
        out = p.communicate()
        yt_ids.append(str(out[0].rstrip()).replace("b'", "").replace("'", ""))
    readme_content = "# White dwarf nova\n"
    for idd in yt_ids:
        readme_content += (
            "[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/"
            + idd
            + "/0.jpg)](http://www.youtube.com/watch?v="
            + idd
            + ")\n"
        )
    with open("README.md", "w") as f:
        f.write(readme_content)
    git.add("README.md")
    git.commit(m="update videos")
    git.push()
开发者ID:bolverk,项目名称:white_dwarf_nova,代码行数:31,代码来源:youtube_github_updater.py


示例2: test_switch_contents_still_there_tracked_commit

 def test_switch_contents_still_there_tracked_commit(self):
   utils_lib.write_file(TRACKED_FP, contents='commit')
   git.commit(TRACKED_FP, m='comment')
   self.repo.switch_current_branch(self.repo.lookup_branch(BRANCH))
   self.assertEqual(TRACKED_FP_CONTENTS_2, utils_lib.read_file(TRACKED_FP))
   self.repo.switch_current_branch(self.repo.lookup_branch('master'))
   self.assertEqual('commit', utils_lib.read_file(TRACKED_FP))
开发者ID:imoapps,项目名称:gitless,代码行数:7,代码来源:test_core.py


示例3: migrate_to_git

def migrate_to_git():
    users = parse_users()
    git_repo = arguments['<git_repo>']

    if not os.path.exists(git_repo):
        os.makedirs(git_repo)
    if not os.path.exists(os.path.join(git_repo, '.git')):
        git.init(git_repo)

    data_dir = os.path.abspath(arguments['<data_dir>'])
    root = os.path.join(data_dir, 'pages')
    pages = os.listdir(root)
    os.chdir(git_repo)
    for page in pages:
        versions = get_versions(page, users=users, data_dir=data_dir)
        if not versions:
            print("### ignoring %s (no revisions found)" % page)
            continue
        path = _unquote(page) + '.rst'
        print("### Creating %s\n" % path)
        dirname, basename = os.path.split(path)
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname)

        for version in versions:
            print("revision %s" % version.pop('revision'))
            with open(path, 'w') as f:
                f.write(version.pop('content'))
            try:
                git.add(path)
                git.commit(path, allow_empty_message=True, **version)
            except:
                pass
开发者ID:ismaelbej,项目名称:moin2git,代码行数:33,代码来源:moin2git.py


示例4: test_merge_conflict

    def test_merge_conflict(self):
        def cleanup_merge_conflict():
            git.checkout("master")
            # if something failed, the branch might still exist
            if self.gd.branch_exists("to_merge_1"):
                git.branch("-D", "to_merge_1")

            if self.gd.branch_exists("to_merge_2"):
                git.branch("-D", "to_merge_2")

        self.addCleanup(cleanup_merge_conflict)

        git.checkout("master")
        git.checkout("-b", "to_merge_1")

        file = open("foo.txt", "w")
        file.write("ABC\n")
        file.close()

        git.add("foo.txt")
        git.commit("-m","Test commit")

        git.checkout("master")

        git.checkout("-b", "to_merge_2")

        file = open("foo.txt", "w")
        file.write("XYZ\n")
        file.close()

        git.add("foo.txt")
        git.commit("-m","Test commit")

        self.assertRaises(MergeException, lambda:  self.gd.merge("to_merge_1", "to_merge_2") )
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:34,代码来源:test_gitdata.py


示例5: add

 def add(self, paths, msg="Intializating"):
     """
         Initializes Directory as repository if not already git repo.
         and adds uncommited changes automatically
     """
     for path in paths:
         global git
         git = git.bake("--git-dir={0}/.git".format(path),
                        "--work-tree={0}".format(path))
         if os.path.isdir(path):
             if not os.path.isdir(path+"/.git"):
                 try:
                     Log.debug(self, "EEGit: git init at {0}"
                               .format(path))
                     git.init(path)
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self, "Unable to git init at {0}"
                               .format(path))
             status = git.status("-s")
             if len(status.splitlines()) > 0:
                 try:
                     Log.debug(self, "EEGit: git commit at {0}"
                               .format(path))
                     git.add("--all")
                     git.commit("-am {0}".format(msg))
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self, "Unable to git commit at {0} "
                               .format(path))
         else:
             Log.debug(self, "EEGit: Path {0} not present".format(path))
开发者ID:1lwebstudio,项目名称:easyengine,代码行数:32,代码来源:git.py


示例6: commit

    def commit(self, objects, message):
        # validate commit message
        if not message or not isinstance(message, basestring):
            raise ValueError("Commit message should not be empty or not string")

        env = os.environ.copy()
        env.update({
                'GIT_WORK_TREE': self.repo,
                'GIT_DIR': '%s/.git' % self.repo,
        })

        git.gc("--prune", _env=env)
        git.checkout("HEAD", _env=env)

        # pull and push from and to the remote
        git.pull("origin", "master", _env=env)

        for obj in objects:
            git.add("-A", obj, _env=env)

        try:
            git.commit("-m", message, _env=env)
        except Exception:
            pass

        git.push(_env=env)
开发者ID:Codevolve,项目名称:pyolite,代码行数:26,代码来源:git.py


示例7: test_merge

    def test_merge(self):
        def cleanup_merge():
            git.checkout("master")
            # if something failed, the branch might still exist
            if self.gd.branch_exists("to_merge_1"):
                git.branch("-D", "to_merge_1")

            git.branch("-D", "base_branch")

        self.addCleanup(cleanup_merge)

        git.checkout("-b", "to_merge_1")
        git.checkout("-b", "base_branch")

        file = open("foo.txt", "w")
        file.write("ABC\n")
        file.close()

        git.add("foo.txt")

        git.commit("-m","Test commit")

        new_sha = self.gd.merge("to_merge_1", "base_branch")

        self.assertTrue( new_sha != "", "new_sha=%s is non-empty" % new_sha)
        self.assertEqual(len(new_sha), 40, "SHA is 40 chars")

        self.assertTrue(True, "Merge succeeded")
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:28,代码来源:test_gitdata.py


示例8: remove_study

    def remove_study(self,study_id, branch, author="OpenTree API <[email protected]>"):
        """Remove a study

        Given a study_id, branch and optionally an
        author, remove a study on the given branch
        and attribute the commit to author.

        Returns the SHA of the commit on branch.

        """
        os.chdir(self.repo)

        study_dir      = "study/%s" % study_id
        study_filename = "%s/%s.json" % (study_dir, study_id)

        if self.branch_exists(branch):
            git.checkout(branch)
            if not os.path.isdir(study_dir):
                # branch already exists locally with study removed
                # so just return the commit SHA
                return git("rev-parse","HEAD").strip()
        else:
            # Create this new branch off of master, NOT the currently-checked out branch!
            git.checkout("master")
            git.checkout("-b",branch)

        git.rm("-rf", study_dir)

        git.commit(author=author, message="Delete Study #%s via OpenTree API" % study_id)

        new_sha = git("rev-parse","HEAD")

        return new_sha.strip()
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:33,代码来源:gitdata.py


示例9: init_repository

def init_repository(url=None):
  """Creates a new Gitless's repository in the cwd.

  Args:
    url: if given the local repository will be a clone of the remote repository
      given by this url.
  """
  cwd = os.getcwd()
  try:
    pygit2.discover_repository(cwd)
    raise GlError('You are already in a Gitless repository')
  except KeyError:  # Expected
    if not url:
      repo = pygit2.init_repository(cwd)
      # We also create an initial root commit
      git.commit(allow_empty=True, m='Initialize repository')
      return repo

    try:
      git.clone(url, cwd)
    except ErrorReturnCode as e:
      raise GlError(stderr(e))

    # We get all remote branches as well and create local equivalents
    repo = Repository()
    remote = repo.remotes['origin']
    for rb in (remote.lookup_branch(bn) for bn in remote.listall_branches()):
      if rb.branch_name == 'master':
        continue
      new_b = repo.create_branch(rb.branch_name, rb.head)
      new_b.upstream = rb
    return repo
开发者ID:imoapps,项目名称:gitless,代码行数:32,代码来源:core.py


示例10: add_to_blacklist

    def add_to_blacklist(self, items_to_blacklist, username, code_permissions):
        # Check if we're on master
        if git("rev-parse", "--abbrev-ref", "HEAD").strip() != "master":
            return (False, "Not currently on master.")

        # Check that we're up-to-date with origin (GitHub)
        git.remote.update()
        if git("rev-parse", "refs/remotes/origin/master").strip() != git("rev-parse", "master").strip():
            return (False, "HEAD isn't at tip of origin's master branch")

        # Check that blacklisted_websites.txt isn't modified locally. That could get ugly fast
        if "blacklisted_websites.txt" in git.status():  # Also ugly
            return (False, "blacklisted_websites.txt modified locally. This is probably bad.")

        # Store current commit hash
        current_commit = git("rev-parse", "HEAD").strip()

        # Add items to file
        with open("blacklisted_websites.txt", "a+") as blacklisted_websites:
            last_character = blacklisted_websites.read()[-1:]
            if last_character != "\n":
                blacklisted_websites.write("\n")
            blacklisted_websites.write("\n".join(items_to_blacklist) + "\n")

        # Checkout a new branch (mostly unnecessary, but may help if we create PRs in the future
        branch = "auto-blacklist-{0}".format(str(time.time()))
        git.checkout("-b", branch)

        # Clear HEAD just in case
        git.reset("HEAD")

        git.add("blacklisted_websites.txt")
        git.commit("-m", "Auto blacklist of {0} by {1} --autopull".format(", ".join(items_to_blacklist), username))

        if code_permissions:
            git.checkout("master")
            git.merge(branch)
            git.push()
        else:
            git.push("origin", branch)
            git.checkout("master")

            if GlobalVars.github_username is None or GlobalVars.github_password is None:
                return (False, "tell someone to set a GH password")

            payload = {"title": "{0}: Blacklist {1}".format(username, ", ".join(items_to_blacklist)),
                       "body": "{0} requests blacklist of domains: \n\n - {1}".format(username, "\n - ".join(items_to_blacklist)),
                       "head": branch,
                       "base": "master"}
            response = requests.post("https://api.github.com/repos/Charcoal-SE/SmokeDetector/pulls", auth=HTTPBasicAuth(GlobalVars.github_username, GlobalVars.github_password), data=json.dumps(payload))
            print(response.json())
            return (True, "You don't have code privileges, but I've [created a pull request for you]({0}).".format(response.json()["html_url"]))

        git.checkout(current_commit)  # Return to old commit to await CI. This will make Smokey think it's in reverted mode if it restarts

        if not code_permissions:
            return (False, "Unable to perform action due to lack of code-level permissions. [Branch pushed](https://github.com/Charcoal-SE/SmokeDetector/tree/{0}), PR at your leisure.".format(branch))

        return (True, "Blacklisted {0} - the entry will be applied via autopull if CI succeeds.".format(", ".join(items_to_blacklist)))
开发者ID:tripleee,项目名称:SmokeDetector,代码行数:59,代码来源:gitmanager.py


示例11: commit

    def commit(self,message="."):
        
        try:
            git.commit(a=True, m=message)
        except ErrorReturnCode_1:
            pass

        return True  
开发者ID:kball,项目名称:ambry,代码行数:8,代码来源:git.py


示例12: setUp

  def setUp(self):
    super(TestRemoteSync, self).setUp()

    utils_lib.write_file('foo', contents='foo')
    git.add('foo')
    git.commit('foo', m='msg')

    self.repo.remotes.create('remote', self.remote_path)
    self.remote = self.repo.remotes['remote']
开发者ID:imoapps,项目名称:gitless,代码行数:9,代码来源:test_core.py


示例13: script_write

def script_write(script, dirname, uid, backup_dir=None):

    dirname = Path(dirname)
    
    if backup_dir is None:
        backup_dir = dirname /  'backup'
    else:
        backup_dir = Path(backup_dir)

    if uid:
        cmd_file = dirname / ('kea2.%s.sh' % uid)
    else:
        cmd_file = dirname / 'kea2.sh'

    if not dirname.exists():
        os.makedirs(dirname)

    try:
        output = git('rev-parse')
        ingit = True
        lg.debug("In a git repository - add & commit the script")
    except ErrorReturnCode as e:
        lg.info("not git - backing up the cmd file")
        ingit = False

    if cmd_file.exists():
        #check if in git:
        if ingit:
            for line in git.status('-s', cmd_file):
                _status, _filename = line.strip().split(None, 1)
                lg.warning('git status prewrite: %s %s', _status, _filename)
                if _filename != cmd_file:
                    lg.warning("this is not the file we want: %s", _filename)
                    continue
                if _status == '??':
                    git.add(cmd_file)
                if _status in ['??', 'A', 'M']:
                    lg.warning("git commit old version of %s", cmd_file)
                    git.commit(cmd_file, m='autocommit by kea2 - prepare for new version')
        else:
            #not in a git repository - copy file to a temp file
            ocf_stat = cmd_file.stat()
            timestamp = time.strftime("%Y-%m-%d_%H:%M:%S",
                                      time.localtime(ocf_stat.st_ctime))
            if not backup_dir.exists():
                os.makedirs(backup_dir)
            new_file_name = backup_dir / ('_kea2.%s.%s.sh' % (uid, timestamp))
            lg.info("rename old %s to %s", cmd_file, new_file_name)
            cmd_file.move(new_file_name)

    script = script.rstrip()
    with open(cmd_file, 'w') as F:
        F.write(script)
        F.write('\n')
    cmd_file.chmod('a+x')
    return cmd_file
开发者ID:mfiers,项目名称:kea2,代码行数:56,代码来源:util.py


示例14: test_create_page_if_remote_added_files

 def test_create_page_if_remote_added_files(self):
     assert not Page.objects.filter(path="newpage.rst").exists()
     with open("newpage.rst", 'w') as p:
         p.write('the new content')
     git.add('.')
     git.commit('-m', 'add new page')
     response = self.client.post(self.url, {})
     # now exists
     new_page = Page.objects.get(path="newpage.rst")
     self.assertEqual(new_page.raw, 'the new content')
开发者ID:Manakel166,项目名称:waliki,代码行数:10,代码来源:test_git_webhook.py


示例15: update

def update(conf, args):
  '''Apply updates from the upstream repository.'''

  print('Checking for updates...')

  # fetch changes from the canonical repo
  git.fetch(constants.GIT_REMOTE, no_tags=True, quiet=True)

  # get a list of the commit messages for the incoming changes
  updates = git('--no-pager', 'log', '..FETCH_HEAD', oneline=True)
  updates = [tuple(m.split(None, 1)) for m in updates.splitlines()]

  # print out a list of the incoming updates
  if len(updates) > 0:
    print('Available updates:')

    max_updates = 10
    for commit, msg in updates[:max_updates]:
      print(color.yellow('*'), msg)

    # print a special message if too many updates are available
    if len(updates) > max_updates:
      print('...and', color.green(len(updates) - max_updates), 'more!')
      print('Run `git log ..FETCH_HEAD` to see the full list')

    # bail if we have uncommitted changes (git exits non-0 in this case)
    if git.diff(exit_code=True, quiet=True, _ok_code=(0, 1)).exit_code != 0:
      raise ValueError('The repository has uncommitted changes. Handle them, '
        'then try updating again.')

    print('Applying the update...')

    # stash _all_ changes to the repo
    git.stash(include_untracked=True, all=True, quiet=True)

    # squash all the fetched commits together and merge them into master
    git.merge('@{u}', squash=True, quiet=True)

    # add a nice update commit that includes the latest upstream commit hash
    commit_message = 'Update dotparty to %s' % updates[0][0]
    git.commit(m=commit_message, quiet=True)

    # TODO: if squash merge failed, roll back to the pre-update state and
    # complain with instructions for the user to do their own update.

    # un-stash all our old changes
    git.stash('pop', quiet=True)

    # push our changes back up to the remote
    git.push(quiet=True)

    print('Update successful!')
  else:
    print('Already up-to-date!')
开发者ID:jasontbradshaw,项目名称:dotparty,代码行数:54,代码来源:dotparty.py


示例16: test_low_level_whatchanged

 def test_low_level_whatchanged(self):
     self.page.raw = "line\n"
     Git().commit(self.page, message=u'"//"')
     another_page = PageFactory(path="another-page.rst")
     another_page.raw = "hello!"
     self.page.raw = "hello 2!"
     git.add(another_page.path)
     git.add(self.page.path)
     git.commit("-m", "commit all")
     wc = Git().whatchanged()
     self.assertEqual(wc[0][3], "commit all")
     self.assertEqual(wc[0][5], [another_page.path, self.page.path])
开发者ID:icotoi,项目名称:waliki,代码行数:12,代码来源:test_git.py


示例17: _release

def _release(language, message, channel):
    print message, "...",
    if _is_dirty():
        sys.exit("Repo must be in clean state before deploying. Please commit changes.")
    _generate_yaml(language, channel)

    if _is_dirty():
        git.add('.travis.yml')
    git.commit(m=message, allow_empty=True)
    git.pull(rebase=True)
    git.push()
    print "done."
开发者ID:anukat2015,项目名称:release,代码行数:12,代码来源:fabfile.py


示例18: update

def update():
    """Update all submodules to Github versions"""
    if _is_dirty():
        sys.exit("Repo must be in clean state before updating. Please commit changes.")
    git.submodule.update(remote=True, rebase=True)
    if _is_dirty():
        print "Updated repositories:"
        print git.status(porcelain=True).strip()
        git.add(all=True)
        git.commit(m="Update submodules to origin")
    else:
        sys.exit('Nothing to update.')
开发者ID:anukat2015,项目名称:release,代码行数:12,代码来源:fabfile.py


示例19: test_edit_file_no_conflict

    def test_edit_file_no_conflict(self):
        # commit remotely
        with open("page.rst", 'w') as p:
            p.write(self.content + '\nhey! edited remotely!\n')
        git.add('.')
        git.commit('-m', 'a remote log')
        # webhook post (this would be done externally)
        response = self.client.post(self.url, {})

        self.assertEqual(self.page.raw, self.content + '\nhey! edited remotely!\n')
        pull_stdout = json.loads(response.content.decode('utf8'))['pull']
        self.assertIn('1 file changed', pull_stdout)
开发者ID:Manakel166,项目名称:waliki,代码行数:12,代码来源:test_git_webhook.py


示例20: update_roles

    def update_roles(self):
        os.chdir('%s/%s' % (self.repo_path, self.ROLES))
        git.pull('-f', '-u', 'origin', 'master')
        os.chdir(self.repo_path)

        message = '%s %s %s %s' % (self.UPDATE, self.ROLES, 'to',
                                   self.get_submodule_hash(self.ROLES))
        git.commit('-m', message, '.gitmodules', self.ROLES)
        sys.stdout.write('Committed %s [%s]\n' % (self.ROLES, message))
        try:
            git.push('origin', 'master')
        except sh.ErrorReturnCode_1:
            pass
开发者ID:gmr,项目名称:remy,代码行数:13,代码来源:roles.py



注:本文中的sh.git.commit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sha.new函数代码示例发布时间:2022-05-27
下一篇:
Python git.checkout函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap