Skip to content

Commit

Permalink
Merge pull request frostming#174 from wkentaro/scm-get-branch
Browse files Browse the repository at this point in the history
Check if git-repo when getting current branch
  • Loading branch information
hickford committed Aug 24, 2015
2 parents 794db26 + 3dd7c14 commit 5cf5121
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 10 additions & 10 deletions legit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def branch_fuzzy_match(b): return b.startswith(branch)
def cmd_switch(args):
"""Legit Switch command."""

from_branch = repo.head.ref.name
from_branch = get_current_branch_name()
to_branch = args.get(0)
to_branch = fuzzy_match_branch(to_branch)

Expand Down Expand Up @@ -157,14 +157,14 @@ def cmd_resync(args):
upstream = fuzzy_match_branch(args.get(0))
if upstream:
is_external = True
original_branch = repo.head.ref.name
original_branch = get_current_branch_name()
else:
print("{0} doesn't exist. Use a branch that does.".format(
colored.yellow(args.get(0))))
sys.exit(1)
else:
upstream = "master"
original_branch = repo.head.ref.name
original_branch = get_current_branch_name()
if repo.is_dirty():
status_log(stash_it, 'Saving local changes.', sync=True)
switch_to(upstream)
Expand All @@ -189,14 +189,14 @@ def cmd_sync(args):
branch = fuzzy_match_branch(args.get(0))
if branch:
is_external = True
original_branch = repo.head.ref.name
original_branch = get_current_branch_name()
else:
print("{0} doesn't exist. Use a branch that does.".format(
colored.yellow(args.get(0))))
sys.exit(1)
else:
# Sync current branch.
branch = repo.head.ref.name
branch = get_current_branch_name()
is_external = False

if branch in get_branch_names(local=False):
Expand Down Expand Up @@ -232,7 +232,7 @@ def cmd_sprout(args):

if new_branch is None:
new_branch = off_branch
off_branch = repo.head.ref.name
off_branch = get_current_branch_name()
else:
off_branch = fuzzy_match_branch(off_branch)

Expand Down Expand Up @@ -274,7 +274,7 @@ def cmd_graft(args):
sys.exit()

if not into_branch:
into_branch = repo.head.ref.name
into_branch = get_current_branch_name()
else:
into_branch = fuzzy_match_branch(into_branch)

Expand Down Expand Up @@ -309,7 +309,7 @@ def cmd_publish(args):
branch = fuzzy_match_branch(args.get(0))

if not branch:
branch = repo.head.ref.name
branch = get_current_branch_name()
display_available_branches()
if args.get(0) is None:
print("Using current branch {0}".format(colored.yellow(branch)))
Expand Down Expand Up @@ -361,7 +361,7 @@ def cmd_harvest(args):
sys.exit()

if to_branch:
original_branch = repo.head.ref.name
original_branch = get_current_branch_name()
is_external = True
else:
is_external = False
Expand Down Expand Up @@ -486,7 +486,7 @@ def display_available_branches():
for branch in branches:

try:
branch_is_selected = (branch.name == repo.head.ref.name)
branch_is_selected = (branch.name == get_current_branch_name())
except TypeError:
branch_is_selected = False

Expand Down
14 changes: 11 additions & 3 deletions legit/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def unstash_index(sync=False, branch=None):
'stash', 'list'])

if branch is None:
branch = repo.head.ref.name
branch = get_current_branch_name()

for stash in stash_list.splitlines():

Expand Down Expand Up @@ -113,7 +113,7 @@ def smart_pull():

repo_check()

branch = repo.head.ref.name
branch = get_current_branch_name()

fetch()

Expand All @@ -124,7 +124,7 @@ def smart_merge(branch, allow_rebase=True):

repo_check()

from_branch = repo.head.ref.name
from_branch = get_current_branch_name()

merges = repo.git.execute([git,
'log', '--merges', '{0}..{1}'.format(branch, from_branch)])
Expand Down Expand Up @@ -237,6 +237,14 @@ def get_remote():
return repo.remote(remote_name)


def get_current_branch_name():
"""Returns current branch name"""

repo_check()

return repo.head.ref.name


def get_branches(local=True, remote_branches=True):
"""Returns a list of local and remote branches."""

Expand Down

0 comments on commit 5cf5121

Please sign in to comment.