voxpupuli / modulesync

Synchronize common files across your Git repositories.
Apache License 2.0
104 stars 48 forks source link

exec command: Only switch branch when cloning #251

Open ekohl opened 2 years ago

ekohl commented 2 years ago

When using msync exec, I was surprised to learn it switched branches. My immediate impression was that it was simply a wrapper that executes commands on checkouts.

This changes the commend to only switch branch when cloning the repository or when it's explicitly passed via the --branch option.

Right now there are no tests (I did verify it manually) because I first want to figure out if this is a good idea. @smortex would you mind having a look?

codecov[bot] commented 2 years ago

Codecov Report

Merging #251 (39b3169) into master (39863fc) will increase coverage by 0.02%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #251      +/-   ##
==========================================
+ Coverage   87.20%   87.22%   +0.02%     
==========================================
  Files          30       30              
  Lines        1016     1018       +2     
==========================================
+ Hits          886      888       +2     
  Misses        130      130              
Impacted Files Coverage Δ
lib/modulesync.rb 98.59% <100.00%> (+0.02%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 39863fc...39b3169. Read the comment docs.

bittner commented 2 years ago

Heads-up: Please make sure you don't break the behavior fixed via #192 and #242.

ekohl commented 2 years ago

Note that this is the exec command. I'm not sure that even takes .sync.yml into account. I thought that file is only needed for rendering templates.

smortex commented 2 years ago

:thinking: quite unexpected as far as I think about it, yes. I had a similar issue but not exactly the same I think and @neomilium demonstrated me I was inconsistent and changing branch was better… Maybe it's not applicable here and maybe it's not applicable anymore anywhere after the recent refactoring, so let's let him shine and enlighten us: is this expected :grin: ?

neomilium commented 2 years ago

exec is a new feature without explicit behavior expected, but the most important thing to me during development was to keep some kind of idempotency / reproductibility. ie. Running the same command at different times and different contexts should produce the same result

My first idea was to set --branch as required option, then I add some kind of flexibility to allow "default" branch to be selected when branch wasn't supplied... I agree with you: it could be unexpected to run it without --branch option but do switch branch.

I'm not so comfortable with the supplied patch as it produce a different behavior if cloned? or not.

Maybe it could be an idea, to implement something like this:

@ekohl It seems we use a different workflow to use msync, if you have some contextualized use case where its relevant to keep current checkout, I do want to ear it.

Nevertheless, I'm OK to merge this if main contributors too, maybe some behavior tests could help to keep the feature when the expected behavior were found.

ekohl commented 2 years ago

@ekohl It seems we use a different workflow to use msync, if you have some contextualized use case where its relevant to keep current checkout, I do want to ear it.

I'll share my previous example. I started work on something that wasn't ready, but I wanted to see the impact. So I started work on a change:

$ msync update --noop -b my-change

Then wanted to figure out what changed, so I ran

$ msync exec -- git diff

This led to unexpected results.

Other actions I can imagine are msync exec -- bundle update && bundle exec rubocop -a && git commit -am 'Rubocop autofix'.

Maybe my core issue is that I like having control over branches. Perhaps similar to msync update, it should have --offline to not perform any git operations. I've already guaranteed that everything is in order with msync update in a previous step.

Nevertheless, I'm OK to merge this if main contributors too, maybe some behavior tests could help to keep the feature when the expected behavior were found.

Any thoughts from @bastelfreak or @alexjfisher? I think you're semi-regular users.