Skip to content

Automatically switch to branch after merge request creation#149

Open
subhajitlucky wants to merge 1 commit into
zigcBenx:masterfrom
subhajitlucky:auto-checkout-mr-51
Open

Automatically switch to branch after merge request creation#149
subhajitlucky wants to merge 1 commit into
zigcBenx:masterfrom
subhajitlucky:auto-checkout-mr-51

Conversation

@subhajitlucky
Copy link
Copy Markdown

Fixes #51.

Summary

  • fetches origin and checks out the created merge request branch automatically
  • falls back to creating the local branch from origin when it does not exist yet
  • adds a regression test for the issue creation flow

Verification

  • python3 -m unittest tests.test_start_issue_creation -v
  • python3 -m unittest discover -v
  • python3 -m compileall gitHappens.py tests
  • git diff --check

Copilot AI review requested due to automatic review settings May 12, 2026 13:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #51 by automatically switching the local git workspace to the newly created merge request’s source branch as part of the issue/MR creation flow, and adds a regression test to ensure the branch switch is triggered.

Changes:

  • Update startIssueCreation to automatically fetch and checkout the created MR source branch.
  • Add a new checkoutBranch helper that fetches origin and checks out/creates the branch locally.
  • Add a unit test covering the issue creation flow to verify the branch switch call occurs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
gitHappens.py Automatically checks out the MR source branch after MR creation and adds checkoutBranch.
tests/test_start_issue_creation.py Adds a regression test ensuring the issue/MR creation flow triggers a branch checkout.
tests/__init__.py Adds a tests package marker file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gitHappens.py
Comment on lines +339 to +340
checkoutBranch(createdMergeRequest['source_branch'])
print(f"Switched to branch {createdMergeRequest['source_branch']}.")
Comment thread gitHappens.py
Comment on lines +344 to +349
def checkoutBranch(branchName):
subprocess.check_call(['git', 'fetch', 'origin'])
try:
subprocess.check_call(['git', 'checkout', branchName])
except subprocess.CalledProcessError:
subprocess.check_call(['git', 'checkout', '-b', branchName, f'origin/{branchName}'])
Comment on lines +10 to +26
root = Path(__file__).resolve().parents[1]
config_dir = root / "configs"
config_dir.mkdir(exist_ok=True)
(config_dir / "config.ini").write_text(
"[DEFAULT]\n"
"base_url=https://gitlab.example\n"
"group_id=1\n"
"custom_template=Custom\n"
"GITLAB_TOKEN=test-token\n"
"squash_commits=true\n"
"delete_branch_after_merge=true\n",
encoding="utf-8",
)
(config_dir / "templates.json").write_text(
'{"templates": [], "reviewers": []}',
encoding="utf-8",
)
Comment on lines +34 to +38
sys.modules["inquirer"] = inquirer_stub

spec = importlib.util.spec_from_file_location("gitHappens_under_test", root / "gitHappens.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatic branch switch on merge request create

2 participants