Sha256: f61bb163a20be9ec1bc7aa70c6f16c6af6db1c8c25af24a356173a761430685e

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'git_shizzle'

describe 'Unstage staged/cached files by index' do

  let(:git) { GitShizzle::Git::Git.new(repo) }
  subject { GitShizzle::QuickGit.new(git) }

  before do
    allow($stdout).to receive(:puts)
  end

  describe 'repository with staged files' do
    before do
      %w{ deleted modified }.each { |f| create f; stage f }
      `git commit --message Blah`

      delete 'deleted'
      stage 'deleted'
      modify 'modified'
      stage 'modified'
      create 'untracked'
      stage 'untracked'

      expect(git.status[0].work_tree_status).to eq(nil)
      expect(git.status[0].index_status).to eq(:deleted)
      expect(git.status[1].work_tree_status).to eq(nil)
      expect(git.status[1].index_status).to eq(:modified)
      expect(git.status[2].work_tree_status).to eq(nil)
      expect(git.status[2].index_status).to eq(:added)
    end

    before do
      allow(git).to receive(:command).and_call_original
      allow(git).to receive(:command).with(/reset/, anything)
    end

    context 'when a staged modified file is unstaged' do
      it 'should run git reset HEAD' do
        subject.unstage 2

        expect(git).to have_received(:command).with('reset HEAD --', ['modified'])
      end
    end

    context 'when a staged deleted file is unstaged' do
      it 'should run git reset HEAD' do
        subject.unstage 1

        expect(git).to have_received(:command).with('reset HEAD --', ['deleted'])
      end
    end

    context 'when a staged new file is unstaged' do
      it 'should run git reset HEAD' do
        subject.unstage 3

        expect(git).to have_received(:command).with('reset HEAD --', ['untracked'])
      end
    end
  end

  describe 'repository without staged files' do
    it 'should fail' do
      expect { subject.unstage 1 }.to raise_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_shizzle-0.2.8 spec/git_shizzle/builtin_commands/unstage_spec.rb