From 982b96972967be0a9cbb5c25c4130e618f6f247e Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Thu, 6 Oct 2005 11:17:50 +0100 Subject: [PATCH] Add git method for switching to a different branch Signed-off-by: Chuck Lever --- stgit/git.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stgit/git.py b/stgit/git.py index bd93330..cc3b55b 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -290,6 +290,23 @@ def create_branch(new_branch, tree_id = None): if os.path.isfile(os.path.join(base_dir, 'MERGE_HEAD')): os.remove(os.path.join(base_dir, 'MERGE_HEAD')) +def switch_branch(name): + """Switch to a git branch + """ + new_head = os.path.join('refs', 'heads', name) + if not branch_exists(new_head): + raise GitException, 'Branch "%s" does not exist' % name + + tree_id = rev_parse(new_head + '^0') + if tree_id != get_head(): + if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0: + raise GitException, 'git-read-tree failed (local changes maybe?)' + __head = tree_id + set_head_file(new_head) + + if os.path.isfile(os.path.join(base_dir, 'MERGE_HEAD')): + os.remove(os.path.join(base_dir, 'MERGE_HEAD')) + def add(names): """Add the files or recursively add the directory contents """ -- 2.11.0