Sha256: 9a85a9e234697274c2a6aac25f1ff0798e0220dd3b864c5e193cb5aba00d31d4
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
difficulty 2 description "获取远程其他同事新创建的特性分⽀的代码,但是不要Merge. 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mygithug-0.5.1 | levels/fetch.rb |