Skip to content

Instantly share code, notes, and snippets.

@eykd
Last active December 13, 2017 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eykd/bd959cbabe91aa690e17 to your computer and use it in GitHub Desktop.
Save eykd/bd959cbabe91aa690e17 to your computer and use it in GitHub Desktop.
Demonstrating weird behavior in git.latest

Steps to reproduce:

Locally:

Set up the VM on step-1 tag:

git clone https://gist.github.com/bd959cbabe91aa690e17.git weird-git
cd weird-git
git checkout step-1
vagrant up
vagrant ssh

On the VM:

Check the state of the VM after the highstate.

cd /opt/stuff/django
git branch  # Should be `stable/1.4.x`:
#   master
# * stable/1.4.x
git log -1  # Should be `5864e1f8e91d31d914c27885240ea6e065b38fd4`
logout

Locally:

Switch to step-2 tag:

git checkout step-2
vagrant ssh

On the VM:

Upgrade Salt to v2015.8.5 and run the highstate.

sudo sh /root/install_salt.sh -P git v2015.8.5
sudo salt-call state.highstate
cd /opt/stuff/django
git branch  # Is still `stable/1.4.x`:
git log -1  # Should be `57671dd0b91ed4def9c7a49c486944f4e98fed9d` (HEAD of stable/1.5.x)

Note the branches now:

#   master
#   origin/stable/1.5.x
# * stable/1.4.x

First of all, this is just weird, and breaks my expectations of common git conventions. When I check out a branch, I expect the local branch to be the name of the branch I checked out, not whatever branch I was on.

Run the highstate again

Here's where it gets weird:

sudo salt-call state.highstate  # This will fail on the `django` state.

OK, so fix that manually:

git checkout 57671dd0b91ed4def9c7a49c486944f4e98fed9d
git branch -d stable/1.4.x
git branch -d origin/stable/1.5.x
sudo salt-call state.highstate  # This will fail again on the `django` state
# fatal: Cannot setup tracking information; starting point is not a branch.

OK, so I guess we need to use that new branch option on the state, right?

logout

Locally:

git checkout step-3
vagrant ssh

On the VM:

sudo salt-call state.highstate  # Success! Fistpump!
sudo salt-call state.highstate  # Failure! Whaaaa?!!
# fatal: A branch named 'origin/stable/1.5.x' already exists.

I've also been able to produce behavior where a branch deploys an old revision, and not the HEAD, when switching between branchs, but I'm not sure how to reproduce it.

fileserver_backend:
- roots
file_client: local
file_roots:
base:
- /opt/salt
pillar_roots:
base:
- /srv
git:
pkg.installed
/root/install_salt.sh:
cmd.run:
- name: wget -O /root/install_salt.sh https://bootstrap.saltstack.com
github.com:
ssh_known_hosts:
- present
- user: vagrant
- fingerprint: 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
/opt/stuff:
file.directory:
- user: vagrant
- group: vagrant
django:
git.latest:
- name: https://github.com/django/django.git
- rev: stable/1.5.x
- branch: stable/1.5.x
- force_clone: true
- force_checkout: true
- force_reset: true
- force_fetch: true
- submodules: true
- target: /opt/stuff/django
- user: vagrant
- require:
- pkg: git
- ssh_known_hosts: github.com
- file: /opt/stuff
#!/bin/sh
start_seconds="$(date +%s)"
if [ ! -d "/etc/salt" ]; then
echo "Bootstrap salt"
wget -O install_salt.sh https://bootstrap.saltstack.com
sudo sh install_salt.sh -P git v2014.7.8
fi
sudo mkdir -p /etc/salt
sudo cp /vagrant/minion.conf /etc/salt/minion
echo "Restart salt-minion"
sudo salt-minion -d
sudo service salt-minion restart
echo "Executing salt highstate (provisioning)"
sudo salt-call state.highstate
end_seconds="$(date +%s)"
echo "-----------------------------"
echo "Provisioning complete in "$(expr $end_seconds - $start_seconds)" seconds"
base:
'*':
- my-env
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :salt_testbed do |web|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
web.vm.box = "ubuntu/precise64"
# Share for masterless salt minion
web.vm.synced_folder "./", "/opt/salt"
web.vm.provision :shell, path: "provision_salt.sh", privileged: false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment