Making Git retain different section content between branches

后端 未结 4 440
难免孤独
难免孤独 2020-11-29 13:54

I\'m developing a Userscript that my employers have asked me to begin to manage via Git.

Right now, I have a stable file and a beta file, so that everyone in the org

相关标签:
4条回答
  • 2020-11-29 14:17

    Delete the @downloadURL line from all files.

    From the @downloadURL documentation, when the line is omitted, Greasemonkey will check the URL that the script was originally loaded from, for updates. The release users will update from the release location and the beta users will update from the beta location.

    If a users wants to switch from one branch to another, he just deletes the script first and then loads from the appropriate branch.

    Likewise, the scripts should not have an @updateURL line either.

    0 讨论(0)
  • 2020-11-29 14:25

    In your repository, create three files, called header.master, header.branch and main.js. Then you can keep different versions of main.js in different branches, but keep the header files the same - one for each branch, and all header files will be in all branches.

    Make a build script, called build.sh, which looks like this:

    #! /bin/sh
    cat header.$(git rev-parse --abbrev-ref HEAD) main.js >myscript.js
    

    Either users must run your build script, or you must provide the prebuilt user script yourself - but I guess you are already doing the latter, since you have a download URL!

    0 讨论(0)
  • 2020-11-29 14:29

    All your changes should be merged except changes to those values, which makes them not like the others, not changes to intrinsic content but deployment-specific changes. Those might be best applied in the post-checkout hook. Here's a sample, a per-branch include processor

    cat <<\EOF >.git/hooks/post-checkout
    #!/bin/sh
    if branch=`git symbolic-ref HEAD --short -q`; then
        for file in `git ls-files -cix*.@branch`; do
            echo "* making ${file%.@branch} from $file with branch-specific includes"
            echo '/^@include-branch-specific ([a-z/]*)$/ { s//cat \1.'$branch'/e }' \
            | sed -rf- $file >${file%.@branch}
        done
    fi
    EOF
    chmod +x .git/hooks/post-checkout
    
    # testing
    git checkout beta
    
    cat  <<\EOF >config.@branch
    // ==UserScript==
    @include-branch-specific config
    // ==/UserScript==
    EOF
    
    echo >config.stable '// @downloadURL  --  StableURL File Location'
    echo >config.beta   '// @downloadURL  --  BetaURL File Location'
    
    git add config.*
    # git rm --cached config
    git commit -m'setting up per-branch configs'
    git checkout
    
    git checkout stable
    git cherry-pick beta
    git checkout
    
    0 讨论(0)
  • 2020-11-29 14:32

    You could write a custom merge driver for git, and configure git to use it - but this would probably be more trouble than it's worth.

    0 讨论(0)
提交回复
热议问题