# Buggy code
def main(*args):
    parser = argparse.ArgumentParser(
        description="""
                Merge (one|many) github pull request by their number.\
                
                If pull request can't be merge as is, cancel merge,
                and continue to the next if any.
                """
    )
    parser.add_argument("-v2", "--githubapiv2", action="store_const", const=2)

    grp = parser.add_mutually_exclusive_group()
    grp.add_argument(
        "-l",
        "--list",
        action="store_const",
        const=True,
        help="list PR, their number and their mergeability",
    )
    grp.add_argument(
        "-a",
        "--merge-all",
        action="store_const",
        const=True,
        help="try to merge as many PR as possible, one by one",
    )
    grp.add_argument(
        "-m",
        "--merge",
        type=int,
        help="The pull request numbers",
        nargs="*",
        metavar="pr-number",
    )
    args = parser.parse_args()

    if args.list:
        pr_list = gh_api.get_pulls_list(gh_project)
        for pr in pr_list:
            mergeable = gh_api.get_pull_request(gh_project, pr["number"])["mergeable"]

            ismgb = "√" if mergeable else " "
            print(
                "* #{number} [{ismgb}]:  {title}".format(
                    number=pr["number"], title=pr["title"], ismgb=ismgb
                )
            )

    if args.merge_all:
        pr_list = gh_api.get_pulls_list(gh_project)
        for pr in pr_list:
            merge_pr(pr["number"])

    elif args.merge:
        for num in args.merge:
            merge_pr(num)

    if not_merged:
        print(
            "*************************************************************************************"
        )
        print(
            "the following branch have not been merged automatically, considere doing it by hand :"
        )
        for num, cmd in not_merged.items():
            print("PR {num}: {cmd}".format(num=num, cmd=cmd))
        print(
            "*************************************************************************************"
        )


# Traceback (subprocess.CalledProcessError)
(master)longs[ipython]> git mpr -m 2179
error: unknown option `no-edit'
usage: git fetch [<options>] [<repository> [<refspec>...]]
or: git fetch [<options>] <group>
or: git fetch --multiple [<options>] [(<repository> | <group>)...]
or: git fetch --all [<options>]

-v, --verbose         be more verbose
-q, --quiet           be more quiet
--all                 fetch from all remotes
-a, --append          append to .git/FETCH_HEAD instead of overwriting
--upload-pack <path>  path to upload pack on remote end
-f, --force           force overwrite of local branch
-m, --multiple        fetch from multiple remotes
-t, --tags            fetch all tags and associated objects
-n                    do not fetch all tags (--no-tags)
-p, --prune           prune remote-tracking branches no longer on remote
--recurse-submodules[=<on-demand>]
control recursive fetching of submodules
--dry-run             dry run
-k, --keep            keep downloaded pack
-u, --update-head-ok  allow updating of HEAD ref
--progress            force progress reporting
--depth <depth>       deepen history of shallow clone

fatal: There is no merge to abort (MERGE_HEAD missing).
Traceback (most recent call last):
File "/home/fperez/usr/bin//git-mpr", line 117, in <module>
main()
File "/home/fperez/usr/bin//git-mpr", line 107, in main
merge_pr(num)
File "/home/fperez/usr/bin//git-mpr", line 46, in merge_pr
branch=branch,
File "/home/fperez/usr/bin//git-mpr", line 29, in merge_branch
check_call(['git', 'merge', '--abort'])
File "/usr/lib/python2.7/subprocess.py", line 511, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'merge', '--abort']' returned non-zero exit status 128

# Fixed code
def main(*args):
    parser = argparse.ArgumentParser(
        description="""
                Merge one or more github pull requests by their number. If any
                one pull request can't be merged as is, its merge is ignored
                and the process continues with the next ones (if any).
                """
    )

    grp = parser.add_mutually_exclusive_group()
    grp.add_argument(
        "-l",
        "--list",
        action="store_const",
        const=True,
        help="list PR, their number and their mergeability",
    )
    grp.add_argument(
        "-a",
        "--merge-all",
        action="store_const",
        const=True,
        help="try to merge as many PR as possible, one by one",
    )
    parser.add_argument(
        "integers",
        type=int,
        help="The pull request numbers",
        nargs="*",
        metavar="pr-number",
    )
    args = parser.parse_args()

    if args.list:
        pr_list = gh_api.get_pulls_list(gh_project)
        for pr in pr_list:
            mergeable = gh_api.get_pull_request(gh_project, pr["number"])["mergeable"]

            ismgb = "√" if mergeable else " "
            print(
                "* #{number} [{ismgb}]:  {title}".format(
                    number=pr["number"], title=pr["title"], ismgb=ismgb
                )
            )

    if args.merge_all:
        pr_list = gh_api.get_pulls_list(gh_project)
        for pr in pr_list:
            merge_pr(pr["number"])

    elif args.merge:
        for num in args.merge:
            merge_pr(num)

    if not_merged:
        print(
            "*************************************************************************************"
        )
        print(
            "the following branch have not been merged automatically, considere doing it by hand :"
        )
        for num, cmd in not_merged.items():
            print("PR {num}: {cmd}".format(num=num, cmd=cmd))
        print(
            "*************************************************************************************"
        )