stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.98k stars 227 forks source link

Create New Branch from the commit #139

Closed ib-ak closed 3 years ago

ib-ak commented 3 years ago

Is your feature request related to a problem? Please describe. Action expects remote branch to be present. It tries to checkout the branch name.

Describe the solution you'd like While switching to "branch" after fetch, if branch is not found,

  1. either, create a branch from checked out branch with new branch name and continue committing (use case: if user needs to work on newly created branch)
  2. or, commit first , create new branch later. (use case: user wants commit on both branches)
  3. or, commit to checked out branch and just add new branch name to git push without creating a new branch (use case: new brance is not used. user can still continue using checkout branch)
    git push origin refs/heads/master:**missingBranch**

Describe alternatives you've considered None

Additional context Add any other context or screenshots about the feature request here.

stefanzweifel commented 3 years ago

Sorry, I can't quite follow your description here. Am I right, that you're doing something link this in your workflow? (See pseudo-code below)

# At the start of the Workflow, the repo is checked out to the default branch
# by using actions/checkout@v2
git checkout main

# You then immediately create/switch to a new branch
git checkout -b other-branch

# You do a thing to your code which you want to automatically commit
touch foo.txt

# You then run git-auto-commit
stefanzweifel/git-auto-commit-action@v4

# You now expect that the `other-branch`-branch exists on GitHub with 
# the changes you made to your code.

It would be awesome if you could share more details of your Workflow or what you want to achieve. We could then write a test case for that and maybe implement the necessary changes.

Meanwhile, have you tried using the branch config for the Action?

- uses: stefanzweifel/git-auto-commit-action@v4
  with:
    branch: feature-123

If you provide a branch option, the Action will create a new branch on remote. https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh#L115

ib-ak commented 3 years ago

I think we are on same page.

I did try branch option with a new branch name it fails here https://github.com/stefanzweifel/git-auto-commit-action/blob/520c63c1719172f8c9682bf244016d9471e7934a/entrypoint.sh#L53

since that branch is not present it cannot do a checkout

stefanzweifel commented 3 years ago

@abhinavkhanna-sf I've created a PR with a possible solution in #140.

Could you please test this in your workflows by updating your workflows like this?

-- uses: stefanzweifel/git-auto-commit-action@v4
+- uses: stefanzweifel/git-auto-commit-action@feature/create-new-branch-during-checkout

If this solves the problem for you, I would tag a new release in the next days.