Skip to content

Remote#branch and #merge should default to current branch instead of master #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/git/remote.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
module Git
class Remote < Path

attr_accessor :name, :url, :fetch_opts

def initialize(base, name)
@base = base
config = @base.lib.config_remote(name)
@name = name
@url = config['url']
@fetch_opts = config['fetch']
end

def fetch(opts={})
@base.fetch(@name, opts)
end

# merge this remote locally
def merge(branch = 'master')
@base.merge("#{@name}/#{branch}")
def merge(branch = @base.current_branch)
remote_tracking_branch = "#{@name}/#{branch}"
@base.merge(remote_tracking_branch)
end

def branch(branch = 'master')
Git::Branch.new(@base, "#{@name}/#{branch}")

def branch(branch = @base.current_branch)
remote_tracking_branch = "#{@name}/#{branch}"
Git::Branch.new(@base, remote_tracking_branch)
end

def remove
@base.lib.remote_remove(@name)
@base.lib.remote_remove(@name)
end

def to_s
@name
end

end
end
49 changes: 49 additions & 0 deletions tests/units/test_remotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,53 @@ def test_push
assert(rem.tag('test-tag'))
end
end

test 'Remote#branch with no args' do
in_temp_dir do
Dir.mkdir 'git'
Git.init('git', initial_branch: 'first', bare: true)
r1 = Git.clone('git', 'r1')
File.write('r1/file1.txt', 'hello world')
r1.add('file1.txt')
r1.commit('first commit')
r1.push

r2 = Git.clone('git', 'r2')

File.write('r1/file2.txt', 'hello world')
r1.add('file2.txt')
r1.commit('second commit')
r1.push

branch = r2.remote('origin').branch

assert_equal('origin/first', branch.full)
end
end

test 'Remote#merge with no args' do
in_temp_dir do
Dir.mkdir 'git'
Git.init('git', initial_branch: 'first', bare: true)
r1 = Git.clone('git', 'r1')
File.write('r1/file1.txt', 'hello world')
r1.add('file1.txt')
r1.commit('first commit')
r1.push

r2 = Git.clone('git', 'r2')

File.write('r1/file2.txt', 'hello world')
r1.add('file2.txt')
r1.commit('second commit')
r1.push

remote = r2.remote('origin')

remote.fetch
remote.merge

assert(File.exist?('r2/file2.txt'))
end
end
end