-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed hg branches should be closed in resulting git repo #84
Comments
Ideally the closedness of branches would be preserved, such that hg
branches and git branch would output the same list.
Git does not have the concept of a closed branch, so it's not something
that can be preserved while converting. Either remove the branch after
conversion or remap the branch name to something like "attic/foo" using
a branch mapping file.
|
@frej Sure, but couldn't you at least add an option for this? We've used hg branches for feature branches, 99% of which get closed and merged back into the default branch. There could be an option to delete the branches in git if they are closed in hg. I'm looking into converting hundreds of hg repos to git, each of which have hundreds or thousands of closed branches. The solution can't be any sort of manual process, that just isn't feasible. |
I'm looking into converting hundreds of hg repos to git, each of which
have hundreds or thousands of closed branches. The solution can't be
any sort of manual process, that just isn't feasible.
I won't oppose a patch adding support for it, but for your needs (which
sounds like a one-time conversion), you could let hg-fast-export convert
all the branches. Then write a script which extracts the closed branches
from hg and just removes them at the git side.
That solution is not practical for incremental conversions, but if
that's what you need, patches are welcome.
|
what you can do is:
and then in the git repo
|
Be careful with this... if a branch was closed and some of it's commits were never merged, those commits become unreachable (dangling) in git, it might not be what you want. You might want to delete only branches that are fully merged and reopen unmerged branches during your export. It depends on your use case. Be careful with branches which names have been sanitized or mapped during conversion. Also be careful if you have a branch that was closed and re-opened, it will show up in closed.txt even if the branch is open in mercurial. |
Just to reiterate from the @mryan43 's comment if you want to delete only branches that are fully merged use |
Small addition to @Kogs suggestion:
|
This might be a better command to find closed branches that have been merged
|
We were solving the same issue and eventually ended up with this query to find closed hg branches:
Here are some corner-cases that led us to this solution:
However, it is important to say that we are detecting closed branches to move them to Finally, here is the snippet of code that moves closed branches to proper namespace:
|
FWIW here's what I did. This deletes all fully-merged branches without any regard for their closed status in mercurial. Note the hard-coded "
from subprocess import check_output, check_call
import sys
USAGE = """Error: invalid arguments.
usage: python delete_branches.py local_repository [remote]
remote defaults to 'origin' if not given."""
try:
REPO = sys.argv[1]
except IndexError:
print(USAGE)
sys.exit(1)
try:
REMOTE = sys.argv[2]
except IndexError:
REMOTE = 'origin'
if len(sys.argv) > 3:
print(USAGE)
sys.exit(1)
# Ensure we know about all remote branches:
check_call(['git', 'fetch', '--prune', REMOTE], cwd=REPO)
# Get a list of all remote branches that are merged into <REMOTE>/master
output = check_output(
[
'git',
'branch',
'-r',
'--merged',
f'{REMOTE}/master',
'--format',
'%(refname:short)',
],
cwd=REPO,
)
branches = output.decode().splitlines()
# Only delete branches from the given remote, and not HEAD or master:
branches_to_delete = []
for branch_path in branches:
remote, branch = branch_path.split('/', 1)
if remote == REMOTE and branch not in ('HEAD', 'master'):
branches_to_delete.append(branch)
# Delete 'em:
for i, branch in enumerate(branches_to_delete):
print(f"({i+1}/{len(branches_to_delete)}) deleting {REMOTE}/{branch}...")
check_call(['git', 'push', REMOTE, '--delete', branch], cwd=REPO) |
The export process results in all named branches in mercurial being created as open branches in git, whether they are currently open or closed in mercurial.
Ideally the closedness of branches would be preserved, such that
hg branches
andgit branch
would output the same list.The text was updated successfully, but these errors were encountered: