Skip to content

Commit

Permalink
Rename the configuration file from .braids to .braids.json.
Browse files Browse the repository at this point in the history
Fixes #48.

Sometimes end users like to inspect and interact with the .braids.json file
directly and would like their editor to detect it as json. The easiest way to
achieve this is to add the .json extension. Existing braid setups are migrated
from the old configuraiton filename to the new one next time the configuration
file is modified in anyway. Typically this is when adding, removing or udpating
a mirror.
  • Loading branch information
realityforge committed Feb 22, 2017
1 parent 833c180 commit 6806c61
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ This is where Braid comes into play. Braid makes it easy to vendor in remote git
repositories and use an automated mechanism for updating the external library
and generating patches to upgrade the external library.

Braid creates a file `.braids` in the root of your repository that contains
Braid creates a file `.braids.json` in the root of your repository that contains
references to external libraries or mirrors. There are two types of mirrors in
Braid: squashed and full. Mirrors are squashed by default, which is what you'll
generally want because they're faster and don't pollute your history with
Expand Down
6 changes: 3 additions & 3 deletions bin/braid
Expand Up @@ -24,7 +24,7 @@ Main {
description <<-TXT
Add a new mirror to be tracked.
* adds metadata about the mirror to .braids
* adds metadata about the mirror to .braids.json
* adds the git remotes to .git/config
* fetches and merges remote code into given directory
Expand Down Expand Up @@ -54,7 +54,7 @@ Main {
* get new changes from remote
* always creates a merge commit
* updates metadata in .braids when revisions are changed
* updates metadata in .braids.json when revisions are changed
Defaults to updating all unlocked mirrors if none is specified.
TXT
Expand All @@ -76,7 +76,7 @@ Main {
description <<-TXT
Remove a mirror.
* removes metadata from .braids
* removes metadata from .braids.json
* removes the local directory and commits the removal
* removes the git remote by default, --keep can be used to suppress that
TXT
Expand Down
3 changes: 2 additions & 1 deletion lib/braid.rb
@@ -1,7 +1,8 @@
require 'braid/version'

module Braid
CONFIG_FILE = '.braids'
OLD_CONFIG_FILE = '.braids'
CONFIG_FILE = '.braids.json'
REQUIRED_GIT_VERSION = '1.6'

def self.verbose
Expand Down
1 change: 1 addition & 0 deletions lib/braid/command.rb
Expand Up @@ -75,6 +75,7 @@ def with_reset_on_error
end

def add_config_file
git.rm(OLD_CONFIG_FILE) if File.exist?(OLD_CONFIG_FILE)
git.add(CONFIG_FILE)
end

Expand Down
24 changes: 15 additions & 9 deletions lib/braid/config.rb
Expand Up @@ -15,19 +15,25 @@ def message
end
end

def initialize(config_file = CONFIG_FILE)
def initialize(config_file = CONFIG_FILE, old_config_files = [OLD_CONFIG_FILE])
@config_file = config_file
begin
store = YAML::Store.new(@config_file)
@db = {}
store.transaction(true) do
store.roots.each do |path|
@db[path] = store[path]
(old_config_files + [config_file]).each do |file|
next unless File.exist?(file)
begin
store = YAML::Store.new(file)
@db = {}
store.transaction(true) do
store.roots.each do |path|
@db[path] = store[path]
end
end
return
rescue
@db = JSON.parse(file)
return if @db
end
rescue
@db = JSON.parse(@config_file)
end
@db = {}
end

def add_from_options(url, options)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/adding_spec.rb
Expand Up @@ -32,7 +32,7 @@
`#{BRAID_BIN} add #{@skit1}`
end

braids = YAML::load_file("#{@shiny}/.braids")
braids = YAML::load_file("#{@shiny}/#{Braid::CONFIG_FILE}")
braids["skit1"]["squashed"].should == true
braids["skit1"]["url"].should == @skit1
braids["skit1"]["revision"].should_not be_nil
Expand Down

0 comments on commit 6806c61

Please sign in to comment.