本文整理汇总了Python中sh.git.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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))
示例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
示例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") )
示例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))
示例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)
示例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")
示例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()
示例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
示例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)))
示例11: commit
def commit(self,message="."):
try:
git.commit(a=True, m=message)
except ErrorReturnCode_1:
pass
return True
示例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']
示例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
示例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')
示例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!')