Skip to content
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

configure branch rules #2709

Closed
JCB-K opened this issue Nov 29, 2023 · 2 comments
Closed

configure branch rules #2709

JCB-K opened this issue Nov 29, 2023 · 2 comments

Comments

@JCB-K
Copy link

JCB-K commented Nov 29, 2023

The remote I push to has restrictions on the format of the branch name. When you forget this you get kind of stuck, see example below.

This could be avoided by applying the same branch name rules locally through git-town.

I'm happy to implement this myself, but I'd need some guidance.

my-repo/ on master
› git-town hack example

[master] git fetch --prune --tags
From gitlab.com:my-org/my-repo
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), 259 bytes | 259.00 KiB/s, done.
   2e973e9d7..11cf748e9  master     -> origin/master

[master] git rebase origin/master
Successfully rebased and updated refs/heads/master.

[master] git branch example master

[master] git checkout example
Switched to branch 'example'


my-repo/ on example
› git-town sync

[example] git fetch --prune --tags

[example] git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

[master] git rebase origin/master
Current branch master is up to date.

[master] git checkout example
Switched to branch 'example'

[example] git merge --no-edit master
Already up to date.

[example] git push -u origin example
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: GitLab: Branch name 'example' does not follow the pattern '^(ftr|enh|fix)-\w[\w-]+\w$'
To gitlab.com:my-org/my-repo
 ! [remote rejected]     example -> example (pre-receive hook declined)
error: failed to push some refs to 'gitlab.com:my-org/my-repo'


Error: exit status 1

To abort, run "git-town abort".
To continue after having resolved conflicts, run "git-town continue".
To continue by skipping the current branch, run "git-town skip".

my-repo/ on example
› git-town rename-branch fix-example
? You have an unfinished `sync` command that ended on the `example` branch 12 seconds ago. Please choose how to proceed Abort the `sync` command


my-repo/ on example
› git-town rename-branch fix-example

[example] git fetch --prune --tags

Error: "example" is not in sync with its tracking branch, please sync the branches before renaming

my-repo/ on example
›
@kevgo
Copy link
Contributor

kevgo commented Nov 29, 2023

Interesting edge case, thanks for reporting it. Technically your example branch shouldn't have a tracking branch since the remote rejected the push. Git Town saying that the branch is not in sync with its tracking branch is a bug in Git Town. I have just fixed this bug in #2710. I hope this solves the issue you report.

Regarding enforcing a convention for branch names, this feels like what Git hooks are for. Here is an example implementation: https://itnext.io/using-git-hooks-to-enforce-branch-naming-policy-ffd81fa01e5e. Does this work for you?

@kevgo
Copy link
Contributor

kevgo commented Apr 13, 2024

Closing this as out of scope for Git Town.

@kevgo kevgo closed this as completed Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants