Skip to content

Commit

Permalink
fix: branch input check tries to switch to branch before failing to a…
Browse files Browse the repository at this point in the history
…ccount for remote branches
  • Loading branch information
wiltonloch committed Jul 16, 2024
1 parent ad21ac2 commit 27499e4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions linhist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import sys
import argparse
import logging
from git import Repo
from git import InvalidGitRepositoryError
from git import Repo, InvalidGitRepositoryError, GitCommandError


def main():
Expand Down Expand Up @@ -57,16 +56,22 @@ def main():
sys.exit(1)

if source not in repository.branches:
logger.error(
'The argument passed to "--source" is not an existing branch in the Git repository'
)
sys.exit(1)
try:
repository.git.switch(source)
except GitCommandError:
logger.error(
'The argument passed to "--source" is not an existing branch in the Git repository'
)
sys.exit(1)

if target not in repository.branches:
logger.error(
'The argument passed to "--target" is not an existing branch in the Git repository'
)
sys.exit(1)
try:
repository.git.switch(target)
except GitCommandError:
logger.error(
'The argument passed to "--target" is not an existing branch in the Git repository'
)
sys.exit(1)

common_ancestor = repository.merge_base(source, target)[0]
target_tip = repository.rev_parse(target)
Expand Down

0 comments on commit 27499e4

Please sign in to comment.