def create_new_branch(new_branch): # Delete it if it exists, not the most elegant solution try: git.branch('-D', new_branch) except BaseException: pass print(f'Creating a branch with the new info') git.checkout('-b', new_branch, SRCPATH)
def get_git(scheme,url,target,overwrite,tag): import git if os.path.exists(target + '/.git'): if not overwrite: return else: if len(scheme) == 1: giturl = url else: giturl = url[4:] git.clone(giturl,target) fs.goto(target) git.fetch() out = git.branch() for line in out.split('\n'): if not line: continue if line[0] != '*': continue out = line.split()[1] break #print out,tag if out != tag: lbranches,rbranches = git.branches() if tag in lbranches: git.checkout(tag) else: # git 1.5 does not put remotes/ like 1.6 does from exception import CommandFailure try: git.checkout('origin/'+tag,tag) except CommandFailure: git.checkout('remotes/origin/'+tag,tag) git.pull() fs.goback() return
def condaenvname(cnf, default=ENV_BRANCH, **kwa): "get the env name" if isinstance(cnf, (list, tuple)): envname = 'unspecified' if '-e' in cnf: envname = cnf[cnf.index('-e') + 1] elif '--envname' in cnf: envname = cnf[cnf.index('--envname') + 1] else: envname = next( (k.split('=')[1] for k in cnf if k.startswith('--envname=')), 'unspecified') else: get = lambda x, y: getattr(getattr(cnf, x, cnf), y, None) envname = kwa.get('envname', None) if not envname: envname = get('options', 'condaenv') if not envname: envname = get('env', 'CONDA_DEFAULT_ENV') if not envname: envname = default if envname.lower() == ENV_BRANCH: envname = branch() if envname == 'master': envname = origin().lower() elif envname.lower() == ENV_ORIGIN: envname = origin().lower() return envname
def checkoutBranch(self,branch,**kwargs): print "checkout branch: %s" % (branch) if "repo" in kwargs: git = kwargs["repo"].git repo=kwargs['repo'] else: git = self.repo.git repo=self.repo print "Repo.active branch=%s" %(repo.active_branch) match=False if repo.active_branch.name != branch: try: b = repo.branches[branch] except IndexError, e: git.branch("-f",branch, "origin/%s" % (branch)) finally:
def test_create_commit_message(): expected_msg = '''\ Implement {} name: {} url: https://leetcode.com/problems/{} difficulty: {} time: {} ms time-rank: {} % time-complexity: {} space: {} MB space-rank: {} % space-complexity: {} Fixes #{} Signed-off-by: {} <{}> '''.format('foo-bar', 'foo-bar', 'foo-bar', 3, 0, 100, 'O(1)', 0, 100, 'O(1)', 42, problem.GIT_USER_NAME, problem.GIT_USER_EMAIL) try: git.branch('-D', 'issue/42/foo-bar') except: pass p = problem.new_problem_args( 'foo-bar', 42, 3, 'class Solution {\npublic:\nint fooBar() {\nreturn 0;\n}\n};\n') p._time = 0 p._time_rank = 100 p._time_complexity = 'O(1)' p._space = 0 p._space_rank = 100 p._space_complexity = 'O(1)' git.checkout(initial_branch) git.branch('-D', 'issue/42/foo-bar') os.remove('foo-bar.cpp') os.remove('foo-bar-test.cpp') actual_msg = p.create_commit_message() assert (actual_msg == expected_msg)
def checkoutBranch(self, branch, **kwargs): print "checkout branch: %s" % (branch) if "repo" in kwargs: git = kwargs["repo"].git repo = kwargs['repo'] else: git = self.repo.git repo = self.repo print "Repo.active branch=%s" % (repo.active_branch) match = False if repo.active_branch.name != branch: try: b = repo.branches[branch] except IndexError, e: git.branch("-f", branch, "origin/%s" % (branch)) finally:
def repo_change_branch(repo_name,my_branch_name): """ Checkout to the branch """ repo=Repo('/home/admin/Desktop/practice/GitPython-0.3.2.RC1/abc/'+repo_name) git = repo.git try: #heads = repo.heads #master = heads.reference #master.commit #master.rename("new_name") git.checkout('HEAD', b=my_branch_name) print "Repo changed to branch"+my_branch_name except Exception,e: print "Branch doesn't exist" git.branch('HEAD', b=my_branch_name) git.checkout('HEAD', b=my_branch_name) print "Branch created and shited too"
def delete(pattern): LOGGER.info(f"Excluindo source(es) {pattern}...") branches = [ branch.replace(" ", "") for branch in git.branch().splitlines() ] branches = list(filter(lambda x: x.startswith(pattern), branches)) [git.execute(["git", "source", "-D", branch]) for branch in branches]
def test_commit_solution(monkeypatch): my_stdin = '0\n100\nO(1)\n0\n100\nO(1)\n' try: git.branch('-D', 'issue/42/foo-bar') except: pass monkeypatch.setattr('sys.stdin', io.StringIO(my_stdin)) p = problem.new_problem_args( 'foo-bar', 42, 3, 'class Solution {\npublic:\nint fooBar() {\nreturn 0;\n}\n};\n') try: git.add('foo-bar.cpp') git.add('foo-bar-test.cpp') problem.commit_solution() except Exception as e: git.checkout(initial_branch) git.branch('-D', p._branch) raise e git.checkout(initial_branch) git.branch('-D', p._branch)
def test_checkout_branch(): try: git.branch('-D', 'issue/42/foo-bar') except: pass args = Problem.default_args() args.issue = 42 args.name = 'foo-bar' p = Problem(args) p.checkout_branch() actual_branch_name = '{}'.format(repo.active_branch) expected_branch_name = 'issue/{}/{}'.format(args.issue, args.name) git.checkout(initial_branch) try: git.branch('-D', expected_branch_name) except: pass assert (actual_branch_name == expected_branch_name)
def shellvars(cnf, defaults=None, **kwa) -> Tuple[Tuple[str, str]]: "return a script for setting the path" if not defaults: defaults = ENV_DEFAULT envname = condaenvname(cnf, default=defaults[0], **kwa) conda = kwa.get('conda', None) if not conda and hasattr(cnf, 'env'): conda = cnf.env.CONDA if conda and isinstance(conda, (list, tuple)): conda = conda[0] if not conda: conda = "conda" avail = { i.strip()[:i.find(' ')]: i.strip()[i.rfind(' ') + 1:] for i in _envnames([conda, 'info', '-e']) if i[0] != '#' and ' ' in i.strip() } brch = branch() orig = origin().lower() if envname not in avail: for i in defaults: envname = (brch if i == ENV_BRANCH else orig if i == ENV_ORIGIN else i) if i == ENV_BRANCH and orig in avail and brch == 'master': envname = orig if envname in avail: break else: envname = ENV_BASE root = Path(avail[envname]) if sys.platform.startswith("win"): binary = root path = (f'{binary};' + ''.join(f'{root/"Library"/i/"bin"};' for i in ('mingw-w64', 'usr', '')) + ''.join(f'{root/i};' for i in ('Scripts', 'bin')) + ';'.join(i for i in os.environ["PATH"].split(';') if 'condabin' in i or 'miniconda3' not in i)) else: binary = root / "bin" path = f'{binary}:{os.environ["PATH"]}' return (('CONDA_DEFAULT_ENV', envname), ('CONDA_PREFIX', str(root)), ('PYTHON_HOST_PROG', str(binary / 'python')), ('PYTHON3_HOST_PROG', str(binary / 'python3')), ('PATH', str(path)))
def start_task(self, identifier): """Sets a task as started, after checking dependencies. Args: identifier: string that uniquely identifies the task. Returns: - If the task was correctly added to the 'WorkingOn' table the recently started task is returned. - Instead, if the task depends from previous uncompleted tasks an informational message is returned. """ task = self._get_task(identifier, "NotStarted") if task: started_task_info = dict(zip(labels, task[0])) depends_from = u.list_from_string( started_task_info["depends_from"]) if not depends_from: started_task_info["started"] = time.strftime("%Y-%m-%d " "%H:%M:%S") started_task = Task(started_task_info, "WorkingOn") status = self.add_task_into("WorkingOn", started_task, True) self.delete_task(identifier) print("Successfully labeled task as started.") git.branch(started_task.info["identifier"]) self.log.add_entry("Created temp branch: OK", "Successfully" " created temp branch.", time.strftime("%Y-%m-%d %H:%M:%S")) if status: if started_task in self.recent_tasks: self.recent_tasks.update(started_task, "WorkingOn") print("Task updated in cache.") self.log.add_entry("Updated in Cache after start: OK.", "Task with id {} successfully" " updated in cache.".format( started_task.info["identifier"] ), time.strftime("%Y-%m-%d %H:%M:%S")) else: self.recent_tasks.push(started_task) print("Task added to cache.") self.log.add_entry("Add to Cache after start: OK.", "Task with id {} successfully" " added to cache.".format( started_task.info["identifier"] ), time.strftime("%Y-%m-%d %H:%M:%S")) return started_task else: print("There were problems when adding the started task" " to the 'WorkingOn' table.") self.log.add_entry("Label task as started: ERROR.", "Task with id {} could not be added to" " the 'WorkingOn' table".format( started_task.info["identifier"]), time.strftime("%Y-%m-%d %H:%M:%S")) else: incomplete_tasks = self._meets_dependencies(depends_from) msg = ("The current task ('{}') depends from ".format( started_task_info["identifier"])) if len(incomplete_tasks) == 1: msg += ("task '{}', which has to be completed before" " starting this task.".format(incomplete_tasks[0])) else: msg += ("tasks {}. Please complete them " "first.".format(incomplete_tasks)) msg = u.replace_last_comma(msg) chars_to_remove = ["[", "]"] for char in chars_to_remove: msg = msg.replace(char, "") return msg else: print("There is no task with that identifier waiting to be" " started.")
def test_references_and_objects(self, rw_dir): # [1-test_references_and_objects] import git repo = git.Repo.clone_from(self._small_repo_url(), os.path.join(rw_dir, 'repo'), branch='master') heads = repo.heads master = heads.master # lists can be accessed by name for convenience master.commit # the commit pointed to by head called master master.rename('new_name') # rename heads master.rename('master') # ![1-test_references_and_objects] # [2-test_references_and_objects] tags = repo.tags tagref = tags[0] tagref.tag # tags may have tag objects carrying additional information tagref.commit # but they always point to commits repo.delete_tag(tagref) # delete or repo.create_tag("my_tag") # create tags using the repo for convenience # ![2-test_references_and_objects] # [3-test_references_and_objects] head = repo.head # the head points to the active branch/ref master = head.reference # retrieve the reference the head points to master.commit # from here you use it as any other reference # ![3-test_references_and_objects] # [4-test_references_and_objects] log = master.log() log[0] # first (i.e. oldest) reflog entry log[-1] # last (i.e. most recent) reflog entry # ![4-test_references_and_objects] # [5-test_references_and_objects] new_branch = repo.create_head('new') # create a new one new_branch.commit = 'HEAD~10' # set branch to another commit without changing index or working trees repo.delete_head(new_branch) # delete an existing head - only works if it is not checked out # ![5-test_references_and_objects] # [6-test_references_and_objects] new_tag = repo.create_tag('my_new_tag', message='my message') # You cannot change the commit a tag points to. Tags need to be re-created self.failUnlessRaises(AttributeError, setattr, new_tag, 'commit', repo.commit('HEAD~1')) repo.delete_tag(new_tag) # ![6-test_references_and_objects] # [7-test_references_and_objects] new_branch = repo.create_head('another-branch') repo.head.reference = new_branch # ![7-test_references_and_objects] # [8-test_references_and_objects] hc = repo.head.commit hct = hc.tree hc != hct hc != repo.tags[0] hc == repo.head.reference.commit # ![8-test_references_and_objects] # [9-test_references_and_objects] assert hct.type == 'tree' # preset string type, being a class attribute assert hct.size > 0 # size in bytes assert len(hct.hexsha) == 40 assert len(hct.binsha) == 20 # ![9-test_references_and_objects] # [10-test_references_and_objects] assert hct.path == '' # root tree has no path assert hct.trees[0].path != '' # the first contained item has one though assert hct.mode == 0o40000 # trees have the mode of a linux directory assert hct.blobs[0].mode == 0o100644 # blobs have a specific mode though comparable to a standard linux fs # ![10-test_references_and_objects] # [11-test_references_and_objects] hct.blobs[0].data_stream.read() # stream object to read data from hct.blobs[0].stream_data(open(os.path.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream # ![11-test_references_and_objects] # [12-test_references_and_objects] repo.commit('master') repo.commit('v0.8.1') repo.commit('HEAD~10') # ![12-test_references_and_objects] # [13-test_references_and_objects] fifty_first_commits = list(repo.iter_commits('master', max_count=50)) assert len(fifty_first_commits) == 50 # this will return commits 21-30 from the commit list as traversed backwards master ten_commits_past_twenty = list(repo.iter_commits('master', max_count=10, skip=20)) assert len(ten_commits_past_twenty) == 10 assert fifty_first_commits[20:30] == ten_commits_past_twenty # ![13-test_references_and_objects] # [14-test_references_and_objects] headcommit = repo.head.commit assert len(headcommit.hexsha) == 40 assert len(headcommit.parents) > 0 assert headcommit.tree.type == 'tree' assert headcommit.author.name == 'Sebastian Thiel' assert isinstance(headcommit.authored_date, int) assert headcommit.committer.name == 'Sebastian Thiel' assert isinstance(headcommit.committed_date, int) assert headcommit.message != '' # ![14-test_references_and_objects] # [15-test_references_and_objects] import time time.asctime(time.gmtime(headcommit.committed_date)) time.strftime("%a, %d %b %Y %H:%M", time.gmtime(headcommit.committed_date)) # ![15-test_references_and_objects] # [16-test_references_and_objects] assert headcommit.parents[0].parents[0].parents[0] == repo.commit('master^^^') # ![16-test_references_and_objects] # [17-test_references_and_objects] tree = repo.heads.master.commit.tree assert len(tree.hexsha) == 40 # ![17-test_references_and_objects] # [18-test_references_and_objects] assert len(tree.trees) > 0 # trees are subdirectories assert len(tree.blobs) > 0 # blobs are files assert len(tree.blobs) + len(tree.trees) == len(tree) # ![18-test_references_and_objects] # [19-test_references_and_objects] assert tree['smmap'] == tree / 'smmap' # access by index and by sub-path for entry in tree: # intuitive iteration of tree members print(entry) blob = tree.trees[0].blobs[0] # let's get a blob in a sub-tree assert blob.name assert len(blob.path) < len(blob.abspath) assert tree.trees[0].name + '/' + blob.name == blob.path # this is how the relative blob path is generated assert tree[blob.path] == blob # you can use paths like 'dir/file' in tree[...] # ![19-test_references_and_objects] # [20-test_references_and_objects] assert tree / 'smmap' == tree['smmap'] assert tree / blob.path == tree[blob.path] # ![20-test_references_and_objects] # [21-test_references_and_objects] # This example shows the various types of allowed ref-specs assert repo.tree() == repo.head.commit.tree past = repo.commit('HEAD~5') assert repo.tree(past) == repo.tree(past.hexsha) assert repo.tree('v0.8.1').type == 'tree' # yes, you can provide any refspec - works everywhere # ![21-test_references_and_objects] # [22-test_references_and_objects] assert len(tree) < len(list(tree.traverse())) # ![22-test_references_and_objects] # [23-test_references_and_objects] index = repo.index # The index contains all blobs in a flat list assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob']) # Access blob objects for (path, stage), entry in index.entries.items(): pass new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name') open(new_file_path, 'w').close() index.add([new_file_path]) # add a new file to the index index.remove(['LICENSE']) # remove an existing one assert os.path.isfile(os.path.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched assert index.commit("my commit message").type == 'commit' # commit changed index repo.active_branch.commit = repo.commit('HEAD~1') # forget last commit from git import Actor author = Actor("An author", "*****@*****.**") committer = Actor("A committer", "*****@*****.**") # commit by commit message and author and committer index.commit("my commit message", author=author, committer=committer) # ![23-test_references_and_objects] # [24-test_references_and_objects] from git import IndexFile # loads a tree into a temporary index, which exists just in memory IndexFile.from_tree(repo, 'HEAD~1') # merge two trees three-way into memory merge_index = IndexFile.from_tree(repo, 'HEAD~10', 'HEAD', repo.merge_base('HEAD~10', 'HEAD')) # and persist it merge_index.write(os.path.join(rw_dir, 'merged_index')) # ![24-test_references_and_objects] # [25-test_references_and_objects] empty_repo = git.Repo.init(os.path.join(rw_dir, 'empty')) origin = empty_repo.create_remote('origin', repo.remotes.origin.url) assert origin.exists() assert origin == empty_repo.remotes.origin == empty_repo.remotes['origin'] origin.fetch() # assure we actually have data. fetch() returns useful information # Setup a local tracking branch of a remote branch empty_repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master) origin.rename('new_origin') # rename remotes # push and pull behaves similarly to `git push|pull` origin.pull() origin.push() # assert not empty_repo.delete_remote(origin).exists() # create and delete remotes # ![25-test_references_and_objects] # [26-test_references_and_objects] assert origin.url == repo.remotes.origin.url cw = origin.config_writer cw.set("pushurl", "other_url") cw.release() # Please note that in python 2, writing origin.config_writer.set(...) is totally safe. # In py3 __del__ calls can be delayed, thus not writing changes in time. # ![26-test_references_and_objects] # [27-test_references_and_objects] hcommit = repo.head.commit hcommit.diff() # diff tree against index hcommit.diff('HEAD~1') # diff tree against previous tree hcommit.diff(None) # diff tree against working tree index = repo.index index.diff() # diff index against itself yielding empty diff index.diff(None) # diff index against working copy index.diff('HEAD') # diff index against current HEAD tree # ![27-test_references_and_objects] # [28-test_references_and_objects] # Traverse added Diff objects only for diff_added in hcommit.diff('HEAD~1').iter_change_type('A'): print(diff_added) # ![28-test_references_and_objects] # [29-test_references_and_objects] # Reset our working tree 10 commits into the past past_branch = repo.create_head('past_branch', 'HEAD~10') repo.head.reference = past_branch assert not repo.head.is_detached # reset the index and working tree to match the pointed-to commit repo.head.reset(index=True, working_tree=True) # To detach your head, you have to point to a commit directy repo.head.reference = repo.commit('HEAD~5') assert repo.head.is_detached # now our head points 15 commits into the past, whereas the working tree # and index are 10 commits in the past # ![29-test_references_and_objects] # [30-test_references_and_objects] # checkout the branch using git-checkout. It will fail as the working tree appears dirty self.failUnlessRaises(git.GitCommandError, repo.heads.master.checkout) repo.heads.past_branch.checkout() # ![30-test_references_and_objects] # [31-test_references_and_objects] git = repo.git git.checkout('HEAD', b="my_new_branch") # create a new branch git.branch('another-new-one') git.branch('-D', 'another-new-one') # pass strings for full control over argument order git.for_each_ref() # '-' becomes '_' when calling it # ![31-test_references_and_objects] # [32-test_references_and_objects] ssh_executable = os.path.join(rw_dir, 'my_ssh_executable.sh') with repo.git.custom_environment(GIT_SSH=ssh_executable): # Note that we don't actually make the call here, as our test-setup doesn't permit it to # succeed. # It will in your case :) repo.remotes.origin.fetch
print(f'Found bionic version {latest_tag}') web_repo = git.Repo("/Users/ahonnecke/Code/repos/web-batch/") git = web_repo.git circlefile = "/Users/ahonnecke/Code/repos/web-batch/docker/Dockerfile.test" for remote in web_repo.remotes: remote.fetch() new_branch = f'bionic-version-{latest_tag}' git.reset('--hard', 'upstream/master') git.checkout('upstream/master') try: git.branch('-D', new_branch) except: pass git.checkout('-b', new_branch, 'upstream/master') with open(circlefile, 'r') as reader: content = reader.read() content_new = re.sub( 'FROM ubuntu:.*', r'FROM ubuntu:' + str(latest_tag), content, flags=re.M ) with open(circlefile, "w") as writer: writer.write(content_new)
def test_create_problem(monkeypatch): solution = \ '''class Solution { public: int fooBar(int z) { } }; ''' my_stdin = 'foo-bar\n42\n3\n' + solution my_stdout = '' try: git.branch('-D', 'issue/42/foo-bar') except: pass monkeypatch.setattr('sys.stdin', io.StringIO(my_stdin)) p = problem.new_problem() assert (p._name == 'foo-bar') assert (p._camel == 'FooBar') assert (p._issue == 42) assert (p._branch == 'issue/42/foo-bar') assert (p._difficulty == Difficulty.HARD) assert (p._problem_template + '\n' == solution) io_fail = False impl_cpp = p._name + '.cpp' test_cpp = p._name + '-test.cpp' if not os.path.exists(impl_cpp): io_fail = True if not os.path.exists(test_cpp): io_fail = True git.checkout(initial_branch) git.branch('-D', p._branch) if io_fail: try: os.remove(impl_cpp) except: pass try: os.remove(test_cpp) except: pass assert (os.path.exists(impl_cpp)) assert (os.path.exists(test_cpp)) os.remove(impl_cpp) os.remove(test_cpp) # expected = '' # expected += 'Enter the problem name: ' # expected += 'Enter the GitHub issue number: ' # expected += 'Enter the difficulty level (1=easy, 2=medium, 3=hard): ' # expected += 'Enter the Solution template: ' # this needs using capsys as a function, but it's already monkeypatch # my_stdout = capsys.readouterr() # assert(my_stdout == expected) assert (p._time == -1) assert (p._time_rank == -1) assert (p._time_complexity == '') assert (p._space == -1) assert (p._space_rank == -1) assert (p._space_complexity == '')
#!/usr/bin/python3 import git import os from config import repo_path, after_pull_instructions repo = git.Repo(repo_path if repo_path != '' else os.getcwd()) def get_latest_remote_commit(repo): return repo.git.ls_remote("--heads", "origin", 'gh-pages').split()[0] def get_latest_local_commit(repo): return repo.commit('gh-pages') if get_latest_local_commit(repo) != get_latest_remote_commit(repo): git = repo.git repo.heads.default.checkout() git.pull('origin', 'default') git.branch('-d', 'gh-pages') git.checkout('-b', 'gh-pages') git.pull('origin', 'gh-pages') if after_pull_instructions: fd = open(after_pull_instructions, 'r') instructions = fd.readlines() for ins in instructions: os.system(ins)
def createBranch(repo, newBranchName): git = repo.git git.branch(newBranchName)
import git git = repo.git git.checkout('HEAD', b="my_new_branch") # create a new branch git.branch('another-new-one') git.branch('-D', 'another-new-one') # pass strings for full control over argument order git.for_each_ref() # '-' becomes '_' when calling it
import subprocess import os import sys import time import shutil import codecs import cgi import webbrowser import argparse import git # g = git.cmd.Git('F:\git\py\git_insights\mcu_project_generator') # print g.pull() import git repo_dir = os.path.abspath('./repo/') test_repo_url = '[email protected]:jsplyy/test.git' test_repo_dir = '/'.join( [repo_dir, test_repo_url.split('/')[-1].split('.')[0]]) print test_repo_dir if not os.path.exists(test_repo_dir): global repo repo = git.Repo.clone_from(test_repo_url, test_repo_dir, recursive=True) else: repo = git.Repo(test_repo_dir) git = repo.git print git.pull() print git.branch()
# couldn't find a good library for pipenv call(['pipenv', 'update', 'ccxt']) with open(lock_file_name) as lockfile: lock_data = lockfile.read() lockfile.close() json_data = json.loads(lock_data) raw_ccxt_version = json_data['default']['ccxt']['version'] latest_ccxt_version = raw_ccxt_version.replace("'", "").replace('=', '') print(f'Current CCXT version is {latest_ccxt_version}') call(['git', 'fetch', '--all']) git.fetch('--all') remote_branches = git.branch('-r') changedFiles = [item.a_path for item in web_repo.index.diff(None)] if current_ccxt_version != latest_ccxt_version: print("Pipfile.lock has changed") new_branch = f'ccxt-{latest_ccxt_version}' full = f'origin/{new_branch}' if full in remote_branches: print(f'"{full}" already exists... bye') exit(0) try: git.branch('-D', new_branch) except:
target_branch = args[2] try: repo = get_repo_object(repo_name, target_branch, options) except git.exc.GitCommandError as e: # Get the git error message from stderr and output the message without # extraneous characters. message = e.stderr.find("fatal:") sys.exit(e.stderr[message:-2]) forward_branch = "forward/" + source_branch git = repo.git # We do not want to use any pre-existing branch. try: git.branch('-D', forward_branch) except: pass git.checkout('HEAD', b=forward_branch) # If using a local repository we want to fetch from the remote. if options.path_to_repo: print "Fetching from remote repository." git.fetch() # TODO: Add merging behavior, see: # http://gitpython.readthedocs.io/en/stable/tutorial.html#using-git-directly # TODO: Add continue option. This should be used after conflicts are resolved. # This will commit and push the changes.