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

Python git.add函数代码示例

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

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



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

示例1: 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


示例2: test_status_performance

  def test_status_performance(self):
    def assert_status_performance():
      # The test fails if `gl status` takes more than 100 times
      # the time `git status` took.
      MAX_TOLERANCE = 100

      t = time.time()
      gl.status()
      gl_t = time.time() - t

      t = time.time()
      git.status()
      git_t = time.time() - t

      self.assertTrue(
          gl_t < git_t*MAX_TOLERANCE,
          msg='gl_t {0}, git_t {1}'.format(gl_t, git_t))

    # All files are untracked
    assert_status_performance()
    # Track all files, repeat
    logging.info('Doing a massive git add, this might take a while')
    git.add('.')
    logging.info('Done')
    assert_status_performance()
开发者ID:imoapps,项目名称:gitless,代码行数:25,代码来源:test_e2e.py


示例3: 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


示例4: 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


示例5: 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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: 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


示例14: 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:mgaitan,项目名称:waliki,代码行数:12,代码来源:test_git.py


示例15: _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


示例16: commit

 def commit(self, path, message='', author=None):
     kwargs = {}
     if isinstance(author, User) and author.is_authenticated():
         kwargs['author'] = "% <%s>" % (author.get_full_name() or author.username)
     elif isinstance(author, six.string_types):
         kwargs['author'] = author
     try:
         git.add(path)
         git.commit(path, m=message or 'Update %s' % path, **kwargs)
     except:
         # TODO: make this more robust!
         # skip when stage is empty
         pass
开发者ID:leliel12,项目名称:waliki,代码行数:13,代码来源:__init__.py


示例17: test_edit_file_with_a_conflict

    def test_edit_file_with_a_conflict(self):
        # commit remotely
        with open("page.rst", 'w') as p:
            p.write(self.content + '\nremote line')
        git.add('.')
        git.commit('-m', 'a remote log')

        # meanwhile. commit a change
        self.page.raw = self.page.raw + '\nlocal line'
        Git().commit(self.page)
        response = self.client.post(self.url, {})
        # local wins
        # Note: newer versions of git don't leave a blank line at the end
        self.assertRegexpMatches(self.content + "\nlocal line\n?$", self.page.raw)
开发者ID:Manakel166,项目名称:waliki,代码行数:14,代码来源:test_git_webhook.py


示例18: install_app

    def install_app(self, appid, pdpobject):
        print "Creating app : %s on heroku" % appid
        r = self._create_app(appid)
        if r.ok:
            print "Successfully created"
        else:
            print "Error creating application"
            print r.status_code, r.text
            return

        resp = r.json()

        git_url = resp["git_url"]
        web_url = resp["web_url"]
        print "Staging PDP archive.."
        print "PDP archive is at : %s" % pdpobject.pdpdir
        print "Configuring git.."
        cwd = os.getcwd()
        os.chdir(pdpobject.pdpdir)
        from sh import git
        git.init()

        print "Invoking the right artifact handler"
        plan = pdpobject.plan
        for a in plan.artifacts:
            h = self.handler_map.get(a.type)
            if h is None:
                raise NotImplementedError("No handler for artifact type : %s" % a.type)
            ho = h(pdpobject, a)
            ho.handle_artifact()

        print "Configuring git remote.."
        git.remote.add("heroku", git_url)


        def process_output(line):
            print(line)

        print "Adding files to repo"
        git.add(".")
        print "Committing to local repo"
        git.commit("-m", "Initial commit")
        print "Pushing to heroku"
        git.push("-u", "heroku", "master", _out=process_output, _tty_out=True)

        print "Uploaded app successfully.."
        print "App is available at : %s" % web_url

        return appid, git_url, web_url
开发者ID:hvishwanath,项目名称:libpaas,代码行数:49,代码来源:heroku.py


示例19: test_git_repo

def test_git_repo():
    # create repo
    repo_dir = tempdir.TempDir()
    gitsh.init(repo_dir.name)
    # put something in the description file:
    description = open('{}/.git/description'.format(repo_dir.name), 'w')
    overwrite(description, 'Depeche Mode')
    # create a single file
    repo_file = tempfile.NamedTemporaryFile(dir=repo_dir.name, delete=False)
    overwrite(repo_file, '123\n')
    # commit it
    gitsh.add(repo_file.name, _cwd=repo_dir.name)
    gitsh.commit(m='message', author='First Last <[email protected]>',
                 _cwd=repo_dir.name)
    return repo_dir
开发者ID:x110dc,项目名称:m6,代码行数:15,代码来源:test_git.py


示例20: main

def main():
    """Script body"""
    app_dir = join(dirname(abspath(__file__)), '..')
    sys.path.append(app_dir)

    from carto_renderer import version  # pylint: disable=import-error

    cur_version = version.SEMANTIC
    if not cur_version.endswith('-SNAPSHOT'):
        raise ValueError('Not a SNAPSHOT version!')
    default_release = cur_version.replace('-SNAPSHOT', '')

    pytest.main(app_dir)

    release_version = prompt(
        'Release version [{ver}]: '.format(ver=default_release),
        r'^\d+[.]\d+[.]\d+$',
        'Release version should be Major.Minor.Patch!',
        default_release)

    split_version = [int(i) for i in release_version.split('.')]
    split_version[2] += 1
    default_next = '.'.join([str(s) for s in split_version]) + '-SNAPSHOT'

    next_version = prompt(
        'Next version [' + default_next + ']: ',
        r'^\d+[.]\d+[.]\d+-SNAPSHOT$',
        'Not a valid SNAPSHOT version!',
        default_next)

    ver_file = join(app_dir, 'carto_renderer', 'version.py')
    set_version(ver_file, cur_version, release_version)
    git.add(ver_file)

    git.commit('-m', 'Setting version to ' + release_version)
    git.tag('v' + release_version)

    set_version(ver_file, release_version, next_version)
    git.add(ver_file)
    git.commit('-m' 'Setting version to ' + next_version)

    do_push = prompt('Push changes to the remote repository (y/n)? [y]: ',
                     '.*', None, 'y')

    if do_push.lower().startswith('y'):
        print(git.push())
        print(git.push('--tags'))
开发者ID:socrata-platform,项目名称:carto-renderer,代码行数:47,代码来源:release.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python git.checkout函数代码示例发布时间:2022-05-27
下一篇:
Python sh.which函数代码示例发布时间: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