Module: Hoe::MercurialHelpers

Includes:
FileUtils, FileUtils::DryRun, RakeHelpers
Included in:
Mercurial
Defined in:
lib/hoe/mercurial.rb

Overview

Mercurial command wrapper functions.

Constant Summary collapse

IGNORE_FILE =

The name of the ignore file

Pathname( '.hgignore' )

Constants included from RakeHelpers

RakeHelpers::ANSI_ATTRIBUTES, RakeHelpers::CLEAR_CURRENT_LINE, RakeHelpers::CLEAR_TO_EOL, RakeHelpers::DEFAULT_EDITOR, RakeHelpers::MULTILINE_PROMPT

Instance Method Summary collapse

Methods included from RakeHelpers

ansi_code, ask_for_confirmation, colorize, edit, error_message, get_target_args, humanize_file_list, log, make_prompt_string, prompt, prompt_for_multiple_values, prompt_with_default, quotelist, read_command_output, run, trace

Instance Method Details

#delete_extra_files(filelist) ⇒ Object

Delete the files in the given filelist after confirming with the user.



423
424
425
426
427
428
429
430
431
# File 'lib/hoe/mercurial.rb', line 423

def delete_extra_files( filelist )
	description = humanize_file_list( filelist, '	 ' )
	log "Files to delete:\n ", description
	ask_for_confirmation( "Really delete them?", false ) do
		filelist.each do |f|
			rm_rf( f, :verbose => true )
		end
	end
end

#edit_commit_log(logfile) ⇒ Object

Generate a commit log and invoke the user’s editor on it.



326
327
328
329
330
331
332
333
334
# File 'lib/hoe/mercurial.rb', line 326

def edit_commit_log( logfile )
	diff = make_commit_log()

	File.open( logfile, 'w' ) do |fh|
		fh.print( diff )
	end

	edit( logfile )
end

#get_current_revObject

Return the ID for the current rev



358
359
360
361
# File 'lib/hoe/mercurial.rb', line 358

def get_current_rev
	id = read_command_output( 'hg', '-q', 'identify' )
	return id.chomp
end

#get_manifestObject



344
345
346
347
# File 'lib/hoe/mercurial.rb', line 344

def get_manifest
	raw = read_command_output( 'hg', 'manifest' )
	return raw.split( $/ )
end

#get_numeric_revObject

Return the current numeric (local) rev number



365
366
367
368
# File 'lib/hoe/mercurial.rb', line 365

def get_numeric_rev
	id = read_command_output( 'hg', '-q', 'identify', '-n' )
	return id.chomp[ /^(\d+)/, 1 ] || '0'
end

#get_repo_pathsObject

Read any remote repo paths known by the current repo and return them as a hash.



379
380
381
382
383
384
385
386
# File 'lib/hoe/mercurial.rb', line 379

def get_repo_paths
	paths = {}
	pathspec = read_command_output( 'hg', 'paths' )
	pathspec.split.each_slice( 3 ) do |name, _, url|
		paths[ name ] = url
	end
	return paths
end

#get_tagsObject

Read the list of existing tags and return them as an Array



372
373
374
375
# File 'lib/hoe/mercurial.rb', line 372

def get_tags
	taglist = read_command_output( 'hg', 'tags' )
	return taglist.split( /\n/ ).collect {|tag| tag[/^\S+/] }
end

#get_tip_infoObject

Get the ‘tip’ info and return it as a Hash



351
352
353
354
# File 'lib/hoe/mercurial.rb', line 351

def get_tip_info
	data = read_command_output( 'hg', 'tip' )
	return YAML.load( data )
end

#get_uncommitted_filesObject

Return the list of files which are not of status ‘clean’



390
391
392
393
394
395
396
# File 'lib/hoe/mercurial.rb', line 390

def get_uncommitted_files
	list = read_command_output( 'hg', 'status', '-n', '--color', 'never' )
	list = list.split( /\n/ )

	trace "Changed files: %p" % [ list ]
	return list
end

#get_unknown_filesObject

Return the list of files which are of status ‘unknown’



400
401
402
403
404
405
406
# File 'lib/hoe/mercurial.rb', line 400

def get_unknown_files
	list = read_command_output( 'hg', 'status', '-un', '--color', 'never' )
	list = list.split( /\n/ )

	trace "New files: %p" % [ list ]
	return list
end

#hg_ignore_files(*pathnames) ⇒ Object

Add the list of pathnames to the .hgignore list.



410
411
412
413
414
415
416
417
418
419
# File 'lib/hoe/mercurial.rb', line 410

def hg_ignore_files( *pathnames )
	patterns = pathnames.flatten.collect do |path|
		'^' + Regexp.escape(path) + '$'
	end
	trace "Ignoring %d files." % [ pathnames.length ]

	IGNORE_FILE.open( File::CREAT|File::WRONLY|File::APPEND, 0644 ) do |fh|
		fh.puts( patterns )
	end
end

#make_changelogObject

Generate a changelog.



338
339
340
341
# File 'lib/hoe/mercurial.rb', line 338

def make_changelog
	log = read_command_output( 'hg', 'log', '--style', 'changelog' )
	return log
end

#make_commit_logObject

Generate a commit log from a diff and return it as a String. At the moment it just returns the diff as-is, but will (someday) do something better.



317
318
319
320
321
322
# File 'lib/hoe/mercurial.rb', line 317

def make_commit_log
	diff = read_command_output( 'hg', 'diff' )
	fail "No differences." if diff.empty?

	return diff
end