barrettj12 / jit

The superior way to use Git.
0 stars 0 forks source link

Add `jit merge` command #39

Open barrettj12 opened 4 months ago

barrettj12 commented 4 months ago

For merging one branch into another. Essentially rewrite this Bash script in Go (but not juju-specific):

```bash #!/bin/bash SOURCE_FILE='merge-juju-source.log' TARGET_FILE='merge-juju-target.log' CONFLICTS_FILE='merge-juju-conflicts.log' DESCR_FILE='merge-juju-description.log' if [[ $1 != '--finish' ]]; then # Start the merge set -eux SOURCE=$1 TARGET=$2 MERGE_BRANCH="merge-$SOURCE-$TARGET-$(date +%Y%m%d)" MSG="chore: merge $SOURCE into $TARGET" # Update branches cd $HOME/git/juju/juju jit pull $SOURCE jit pull $TARGET jit new $MERGE_BRANCH $TARGET cd $HOME/git/juju/juju/$MERGE_BRANCH set +e git merge $SOURCE -m "$MSG" # TODO: use imerge but we need to collect all the conflicts # git-imerge merge $SOURCE --name "merge-$SOURCE-$TARGET-$(date +%Y%m%d%H%M%S)" # save args and conflict list for later echo $SOURCE > $SOURCE_FILE echo $TARGET > $TARGET_FILE git diff --name-only --diff-filter=U --relative | tee $CONFLICTS_FILE else # Complete the merge SOURCE=$(cat $SOURCE_FILE) TARGET=$(cat $TARGET_FILE) MSG="chore: merge $SOURCE into $TARGET" CONFLICTS=$(cat $CONFLICTS_FILE) git push barrettj12 -u # Generate description # empty the file > $DESCR_FILE echo "Merges the following patches:" | tee -a $DESCR_FILE for PR_REF in $(git log $TARGET..HEAD --oneline | grep -Po '#\d+'); do echo "- $PR_REF" | tee -a $DESCR_FILE done echo | tee -a $DESCR_FILE echo "### Conflicts" | tee -a $DESCR_FILE for FILE in $CONFLICTS; do echo "- $FILE" | tee -a $DESCR_FILE done if [[ -z $CONFLICTS ]]; then echo "None." | tee -a $DESCR_FILE fi gh pr create --repo juju/juju --base $TARGET --title "$MSG" --body-file $DESCR_FILE fi ```

We will need a config value for setting the merge message, possibly using Go templates.

barrettj12 commented 3 months ago

We could also have a config value for setting the merge branch name, and the description.

The information about the merge (e.g. source/target branches, conflicts) should be stored in the repo's .jit folder. Maybe .jit/merges/<merge-name>