emonpi icon indicating copy to clipboard operation
emonpi copied to clipboard

Setting upstream branch tracking info

Open TrystanLea opened this issue 5 years ago • 17 comments

In attempting to automate the switching of the postprocess, device and sync modules to newly created stable branches I came across an issue caused by for some reason certain repositories not having upstream branch tracking info set. This meant I could not pull in all branches and switch to the newly created stable branches.

The solution I found to work was the following: https://github.com/openenergymonitor/emonpi/compare/923e05deeb9ea5945b5493c665f21a20f6be182c..master

I needed to run:

git branch --set-upstream-to=origin/$branch

and then:

git pull

without the branch specific pull, it was then possible to run:

git checkout stable 

@borpin what do you think of this solution? Its a shame to pollute every emonpiupdate log with:

Branch stable set up to track remote branch stable from origin.

but it does seem to work well.

TrystanLea avatar Sep 26 '19 15:09 TrystanLea

PS: @borpin im sure you will be happy with the new stable branches. Im thinking of adding a feature to select stable, master or auto from the emoncms UI to make switching between stable/master on a global level easier.

TrystanLea avatar Sep 26 '19 15:09 TrystanLea

On changing from UI - great! I was thinking of an advanced update page that would allow a per repo brach selection option.

Not come across this problem with git. Can't try till Sunday. Can you tell me what you tried that failed?

Did you try a git fetch --all (from memory)?

Might be how the initial clone was done in the past. Is it a problem on a fresh scripted install?

borpin avatar Sep 27 '19 07:09 borpin

Thanks @borpin yes I tried git fetch -all, not quite sure why that didnt work. Im also away until Sunday now. Will reply with more detail then.

TrystanLea avatar Sep 27 '19 08:09 TrystanLea

So I have just had a go on an emonpi setup, created by the script (I think) a while back.

I've included a screenshot as the colour helps explain things.

TL:DR It should work by simply using git fetch (not git pull) first which gets all of the repo info and then a git checkout <branch>. Caveat the git version is important as it was a feature added at some point.

The oddity is that it talks about a 'new' branch, but I don't think it really means that, rather that it has created a new local branch that is tracking a remote branch (if you see what I mean).

pi@emonpi:/var/www/emoncms $ cd Modules/device/
pi@emonpi:/var/www/emoncms/Modules/device $ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/emoncmsorg
  remotes/origin/indexedinputs
  remotes/origin/master
  remotes/origin/remove_user_dependency
pi@emonpi:/var/www/emoncms/Modules/device $ git fetch
From https://github.com/emoncms/device
 * [new branch]      stable     -> origin/stable
pi@emonpi:/var/www/emoncms/Modules/device $ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/emoncmsorg
  remotes/origin/indexedinputs
  remotes/origin/master
  remotes/origin/remove_user_dependency
  remotes/origin/stable
pi@emonpi:/var/www/emoncms/Modules/device $ git checkout stable
Branch stable set up to track remote branch stable from origin.
Switched to a new branch 'stable'
pi@emonpi:/var/www/emoncms/Modules/device $ git branch -a
  master
* stable
  remotes/origin/HEAD -> origin/master
  remotes/origin/emoncmsorg
  remotes/origin/indexedinputs
  remotes/origin/master
  remotes/origin/remove_user_dependency
  remotes/origin/stable
pi@emonpi:/var/www/emoncms/Modules/device $

image

Finally this looks correct.

pi@emonpi:/var/www/emoncms/Modules/device $ git remote show origin
* remote origin
  Fetch URL: https://github.com/emoncms/device
  Push  URL: https://github.com/emoncms/device
  HEAD branch: master
  Remote branches:
    emoncmsorg             tracked
    indexedinputs          tracked
    master                 tracked
    remove_user_dependency tracked
    stable                 tracked
  Local branches configured for 'git pull':
    master merges with remote master
    stable merges with remote stable
  Local refs configured for 'git push':
    master pushes to master (up to date)
    stable pushes to stable (up to date)

I will do the same for the postprocess folder...

pi@emonpi:/var/www/emoncms/Modules $ cd postprocess
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git remote show origin
* remote origin
  Fetch URL: https://github.com/emoncms/postprocess
  Push  URL: https://github.com/emoncms/postprocess
  HEAD branch: master
  Remote branches:
    emoncmsorg tracked
    emonpi     tracked
    master     new (next fetch will store in remotes/origin)
    stable     new (next fetch will store in remotes/origin)
  Local branch configured for 'git pull':
    emonpi merges with remote emonpi
  Local ref configured for 'git push':
    emonpi pushes to emonpi (up to date)
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git branch -a
* emonpi
  remotes/origin/HEAD -> origin/emonpi
  remotes/origin/emoncmsorg
  remotes/origin/emonpi
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git fetch
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 18 (delta 7), reused 13 (delta 5), pack-reused 0
Unpacking objects: 100% (18/18), done.
From https://github.com/emoncms/postprocess
 * [new branch]      master     -> origin/master
 * [new branch]      stable     -> origin/stable
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git branch -a
* emonpi
  remotes/origin/HEAD -> origin/emonpi
  remotes/origin/emoncmsorg
  remotes/origin/emonpi
  remotes/origin/master
  remotes/origin/stable
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git remote show origin
* remote origin
  Fetch URL: https://github.com/emoncms/postprocess
  Push  URL: https://github.com/emoncms/postprocess
  HEAD branch: master
  Remote branches:
    emoncmsorg tracked
    emonpi     tracked
    master     tracked
    stable     tracked
  Local branch configured for 'git pull':
    emonpi merges with remote emonpi
  Local ref configured for 'git push':
    emonpi pushes to emonpi (up to date)
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git checkout stable
Branch stable set up to track remote branch stable from origin.
Switched to a new branch 'stable'
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git remote show origin
* remote origin
  Fetch URL: https://github.com/emoncms/postprocess
  Push  URL: https://github.com/emoncms/postprocess
  HEAD branch: master
  Remote branches:
    emoncmsorg tracked
    emonpi     tracked
    master     tracked
    stable     tracked
  Local branches configured for 'git pull':
    emonpi merges with remote emonpi
    stable merges with remote stable
  Local refs configured for 'git push':
    emonpi pushes to emonpi (up to date)
    stable pushes to stable (up to date)
pi@emonpi:/var/www/emoncms/Modules/postprocess $ git branch -a
  emonpi
* stable
  remotes/origin/HEAD -> origin/emonpi
  remotes/origin/emoncmsorg
  remotes/origin/emonpi
  remotes/origin/master
  remotes/origin/stable
pi@emonpi:/var/www/emoncms/Modules/postprocess $

borpin avatar Sep 30 '19 15:09 borpin

As an aside, could you update all of the master branches so the version number is +1 & 'beta' please @TrystanLea?

borpin avatar Sep 30 '19 15:09 borpin

updated version: https://github.com/emoncms/emoncms/commit/b925f6e067c748a46a1f890e237b7bda52e2589e

TrystanLea avatar Oct 01 '19 13:10 TrystanLea

I previously updated the versions for the other modules e.g: https://github.com/emoncms/sync/commit/39361e49afb6b0cc293ad4b021895f02dc758be5 just somehow forgot the main repo

TrystanLea avatar Oct 01 '19 14:10 TrystanLea

If I run git fetch and then git checkout it gives me this message, so looks like git pull is required.

------------------------------------------
Updating /var/www/emoncms/Modules/wifi module
------------------------------------------
Fetching origin
- git branch: master
- git tags: 2.0.0-28-g16c75d2
- no local changes

Already on 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

TrystanLea avatar Oct 01 '19 14:10 TrystanLea

I previously updated the versions for the other modules

It was other modules I found - Emoncms/device has the same version for master & stable.

I see you updated WiFi a few minutes ago but left off the 'beta' :grinning:.

borpin avatar Oct 01 '19 14:10 borpin

If I run git fetch and then git checkout it gives me this message, so looks like git pull is required.

Use the prune command to help clean it up.

Yes, I think it will. I couldn't test that as stable and master were the same!

borpin avatar Oct 01 '19 14:10 borpin

I think it is partly because the original clone targets a specific branch.

borpin avatar Oct 01 '19 14:10 borpin

I see you updated WiFi a few minutes ago but left off the 'beta' grinning.

Yes I don’t want to add the beta to all modules, I think we just keep to updating the version on the module master branches after making a change and then merge to stable when ready.

TrystanLea avatar Oct 01 '19 14:10 TrystanLea

Use the prune command to help clean it up.

prune command is already in there:

git fetch --prune --all

TrystanLea avatar Oct 01 '19 14:10 TrystanLea

Yes I don’t want to add the beta to all modules

Ok but it then will get really confusing when looking at current state of Modules. At least a 'b' would immediately identify that the Module was pulled from master as opposed to stable.

borpin avatar Oct 01 '19 15:10 borpin

I was thinking that we need to attach the branch to the version in the module list. That would be a good thing to add alongside the ability to change between stable/master on a global level via the UI.

TrystanLea avatar Oct 01 '19 16:10 TrystanLea

Can do. Could also make it clearer what are 'core' and what are 'addons'.

One per line, perhaps hold a 'manifest' type file that lists all modules available and then the version number if installed in the UI.

Perhaps:

Module name (with URL) Version Branch Git Describe
Emoncms Version: low-write 10.1.7 master 10.1.6-125-g6274f797
backup v2.0.0 stable xxxxxxx

TBH I would not list the core modules, just the add-ons.

borpin avatar Oct 01 '19 22:10 borpin

yes I think that would be really nice and I agree better without core modules, just the add-ons

TrystanLea avatar Oct 02 '19 08:10 TrystanLea