frostming / frostming/legit

git sync fails badly, not goodly, when branch is unpublished

Open
#271 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.7k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

I am using legit version 1.2.0post0 installed from pip. When I have a branch that is unpublished, git sync fails badly:

lousyd $ git status
On branch 174-branchname
Your branch is up to date with 'origin/174-branchname'.

nothing to commit, working tree clean

lousyd $ git branches
   172-some-other-branch                  (published)    
*  174-branchname                         (unpublished)  
   179-another-branch                     (published)    

lousyd $ git pull --all
Fetching origin
Your configuration specifies to merge with the ref 'refs/heads/174-branchname'
from the remote, but no such ref was fetched.

lousyd $ git sync
Pulling commits from the server.
Traceback (most recent call last):
  File "/home/lousyd/.local/bin/legit", line 8, in <module>
    sys.exit(cli())
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/legit/cli.py", line 167, in sync
    status_log(scm.smart_pull, 'Pulling commits from the server.')
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/legit/utils.py", line 14, in status_log
    log = func(*args, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/legit/scm.py", line 137, in smart_pull
    self.smart_merge_enabled())
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/legit/scm.py", line 151, in smart_merge
    ['log', '--merges', '{}..{}'.format(branch, from_branch)])
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/legit/scm.py", line 60, in git_exec
    result = self.repo.git.execute(command, **kwargs)
  File "/home/lousyd/.local/share/virtualenvs/pip-fh2szxJc/lib/python3.6/site-packages/git/cmd.py", line 823, in execute
    raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git log --merges origin/174-branchname..174-branchname
  stderr: 'fatal: ambiguous argument 'origin/174-branchname..174-branchname': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]''

ttwalto $ git publish 174-branchname
Publishing 174-branchname.
Branch '174-branchname' set up to track remote branch '174-branchname' from 'origin'.

ttwalto $ git sync
Pulling commits from the server.
Current branch 174-branchname is up to date.
Pushing commits to the server.

It would be helpful for sync to give a friendlier and more informative error, like:

Error: Branch 174-branchname is not published. Use a branch that is already published.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sync entry point in legit/cli.py, then follow smart_pull and smart_merge in legit/scm.py, as shown in the traceback. Reproduce the unpublished-branch case with git sync and make the failure report that the branch is not published instead of exposing a GitCommandError.】【。

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.