Sha256: 256aa26013ca1162483820eb129b748485b17796dff49cb3101d4ebc8519ad2a

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

difficulty 2
description "Looks like a new branch was pushed into our remote repository. Get the changes without merging them with the local repository "

setup do
  # remember the working directory so we can come back to it later
  cwd = Dir.pwd
  # initialize another git repo to be used as a "remote"
  tmpdir = Dir.mktmpdir

  # local repo
  repo.init

    #adds a file to origin/master
  FileUtils.touch "master_file"
  repo.add        "master_file"
  repo.commit_all 'Commits master_file'

  # remote repo
  Dir.chdir tmpdir
  repo.init

  #adds a file to origin/master
  FileUtils.touch "master_file"
  repo.add        "master_file"
  repo.commit_all 'Commits master_file'
  
  #adds remote repo
  Dir.chdir cwd
  `git remote add origin #{tmpdir}/.git`
  `git fetch origin --quiet`
  `git branch -u origin/master master 2> /dev/null`

  Dir.chdir tmpdir
  # create a new branch in the remote repo
  `git checkout -b new_branch --quiet`

  # adds a file into the new branch.  Should not be pulled into the local
  FileUtils.touch "file1"
  repo.add        "file1"
  repo.commit_all 'Commits file 1'
  
end

solution do
  repo.init
  result = true


  # counts the number of local branches. Should equal 1
  local_branches = repo.branches.size

  # after a git fetch command, each branch will be stored in in the .git/FETCH_HEAD file. Each branch is on its own line
  # This command will count the number of lines, which will give the number of branches 
  if File.file?('.git/FETCH_HEAD') #checks for file existance
  	num_remote = File.read(".git/FETCH_HEAD").split("\n").count
  else
  	num_remote = 0
  end

  # there should be 1 local branch and 2 remote branches for a success condition
  if local_branches == 1 and num_remote == 2
  	result = true
  else
  	result = false
  end 
end

hint do
  puts "Look up the 'git fetch' command"
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
githug-0.5.0 levels/fetch.rb
githug-0.4.8 levels/fetch.rb
githug-0.4.7 levels/fetch.rb
githug-0.4.6 levels/fetch.rb
githug-0.4.5 levels/fetch.rb
githug-0.4.4 levels/fetch.rb