Skip to content

Commit

Permalink
Actually check if local branch is up to date
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
piotrgredowski committed May 9, 2019
1 parent 85d58df commit c95acb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This script will check if current commits of specified local repos are the same
- `python>=3.6`
- `python3-pip`
- `sudo`
- `git`

## Installation

Expand Down
20 changes: 5 additions & 15 deletions check_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,20 @@
ICON_LOADING = Image.open(os.path.join(curr_dir, './images/loading.png'))


def execute_command(command: str, cwd: str, with_stdout=False):
if with_stdout:
stdout = subprocess.PIPE
else:
stdout = None

output = subprocess.run(command.split(" "), cwd=cwd, stdout=stdout).stdout

if with_stdout:
return output.decode('utf-8')
def execute_command(command: str, cwd: str):
return subprocess.run(command.split(" "), cwd=cwd)


def repo_is_up_to_date(repo: utils.Repo):
commands = {
"fetch": "git fetch",
"origin": f"git rev-parse origin/{repo.branch}",
"local": f"git rev-parse {repo.branch}",
"is_up_to_date": f"git merge-base --is-ancestor origin/{repo.branch} {repo.branch}",
}

execute_command(commands["fetch"], cwd=repo.path)
origin_commit_id = execute_command(commands["origin"], cwd=repo.path, with_stdout=True)
local_commit_id = execute_command(commands["local"], cwd=repo.path, with_stdout=True)
returncode = execute_command(commands["is_up_to_date"], cwd=repo.path).returncode

return origin_commit_id == local_commit_id
return returncode == 0


def send_notification(text):
Expand Down

0 comments on commit c95acb9

Please sign in to comment.